Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
METRON-2302 [UI] Change the default polling interval for Alerts UI to…
Browse files Browse the repository at this point in the history
… longer time (tiborm via sardell) closes #1547
  • Loading branch information
tiborm authored and sardell committed Oct 31, 2019
1 parent df6e181 commit eb1dda6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { Spy } from 'jasmine-core';
import { DialogService } from 'app/service/dialog.service';
import { RestError } from 'app/model/rest-error';
import { DialogType } from 'app/model/dialog-type';
import { RefreshInterval } from 'app/alerts/configure-rows/configure-rows-enums';

const DEFAULT_POLLING_INTERVAL = RefreshInterval.TEN_MIN;

class QueryBuilderFake {
private _filter = '';
Expand Down Expand Up @@ -447,13 +450,13 @@ describe('AutoPollingService', () => {
it('should persist polling state on start', () => {
spyOn(localStorage, 'setItem');
autoPollingService.start();
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', '{"isActive":true,"refreshInterval":10}');
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', `{"isActive":true,"refreshInterval":${DEFAULT_POLLING_INTERVAL}}`);
});

it('should persist polling state on stop', () => {
spyOn(localStorage, 'setItem');
autoPollingService.stop();
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', '{"isActive":false,"refreshInterval":10}');
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', `{"isActive":false,"refreshInterval":${DEFAULT_POLLING_INTERVAL}}`);
});

it('should persist polling state on interval change', () => {
Expand All @@ -464,7 +467,7 @@ describe('AutoPollingService', () => {

it('should restore polling state on construction', () => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":443}');

Expand All @@ -477,7 +480,7 @@ describe('AutoPollingService', () => {

it('should start polling on construction when persisted isActive==true', fakeAsync(() => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(searchServiceFake, 'search').and.callThrough();
spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":10}');
Expand All @@ -486,18 +489,18 @@ describe('AutoPollingService', () => {

expect(searchServiceFake.search).toHaveBeenCalledTimes(1);

tick(getIntervalInMS());
tick(localAutoPollingSvc.getInterval() * 1000);
expect(searchServiceFake.search).toHaveBeenCalledTimes(2);

tick(getIntervalInMS());
tick(localAutoPollingSvc.getInterval() * 1000);
expect(searchServiceFake.search).toHaveBeenCalledTimes(3);

localAutoPollingSvc.stop();
}));

it('should start polling on construction with the persisted interval', fakeAsync(() => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(searchServiceFake, 'search').and.callThrough();
spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":4}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { POLLING_DEFAULT_STATE } from 'app/utils/constants';
import { RestError } from 'app/model/rest-error';
import { DialogType } from 'app/shared/metron-dialog/metron-dialog.component';
import { DialogService } from 'app/service/dialog.service';
import { RefreshInterval } from '../../configure-rows/configure-rows-enums';

interface AutoPollingStateModel {
isActive: boolean,
Expand All @@ -36,7 +37,7 @@ export class AutoPollingService {
data = new Subject<SearchResponse>();

private isCongestion = false;
private refreshInterval = 10;
private refreshInterval = RefreshInterval.TEN_MIN;
private isPollingActive = POLLING_DEFAULT_STATE;
private isPending = false;
private isPollingSuppressed = false;
Expand Down

0 comments on commit eb1dda6

Please sign in to comment.