Skip to content

Commit

Permalink
Merge db87c4c into db0148b
Browse files Browse the repository at this point in the history
  • Loading branch information
mychalhackman committed Sep 10, 2019
2 parents db0148b + db87c4c commit 237e7c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
32 changes: 1 addition & 31 deletions projects/core/src/lib/idle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,10 @@ describe('core/Idle', () => {

instance.setTimeout(3);
instance.setInterrupts([source]);

expiry.mockNow = new Date();
instance.watch();

expect(source.isAttached).toBe(true);

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(30000);
tick(1000);
tick(1000);
Expand Down Expand Up @@ -411,12 +406,9 @@ describe('core/Idle', () => {
spyOn(instance.onTimeout, 'emit').and.callThrough();

instance.setTimeout(3);
expiry.mockNow = new Date();
instance.watch();

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);

tick(3000);
expect(instance.isIdling()).toBe(true);

Expand All @@ -434,12 +426,8 @@ describe('core/Idle', () => {
spyOn(instance.onTimeout, 'emit').and.callThrough();

instance.setTimeout(3);
expiry.mockNow = new Date();
instance.watch();

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(3000);
expect(instance.isIdling()).toBe(true);

Expand All @@ -456,12 +444,8 @@ describe('core/Idle', () => {
spyOn(instance.onInterrupt, 'emit').and.callThrough();

instance.setTimeout(3);
expiry.mockNow = new Date();
instance.watch();

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(3000);
expect(instance.isIdling()).toBe(true);

Expand Down Expand Up @@ -499,12 +483,8 @@ describe('core/Idle', () => {
spyOn(instance.onTimeoutWarning, 'emit').and.callThrough();

instance.setTimeout(3);
expiry.mockNow = new Date();
instance.watch();

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(3000);
// we're going to check that it's idling, then force it to not be
expect(instance.isIdling()).toBe(true);
Expand Down Expand Up @@ -653,14 +633,9 @@ describe('core/Idle', () => {
instance.setAutoResume(AutoResume.notIdle);
instance.setIdle(3);

const now = new Date();
expiry.mockNow = now;
instance.watch();
spyOn(instance, 'watch').and.callThrough();

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(2000);

expect(instance.isIdling()).toBe(false);
Expand Down Expand Up @@ -827,13 +802,8 @@ describe('core/Idle', () => {
}));

it('should stop keepalive when timed out', fakeAsync(() => {
expiry.mockNow = new Date();
instance.watch();
expect(svc.isRunning).toBe(true);

expiry.mockNow = new Date(
expiry.now().getTime() + instance.getIdle() * 1000
);
tick(3000);
tick(1000);
tick(1000);
Expand Down
12 changes: 7 additions & 5 deletions projects/core/src/lib/idle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ export class Idle implements OnDestroy {
const diff = this.getExpiryDiff(timeout);
if (diff > 0) {
this.safeClearInterval('idleHandle');
this.setIdleIntervalOutsideOfZone(watchFn, diff);
this.setIdleIntervalOutsideOfZone(watchFn, 1000);
} else {
this.toggleState();
}
});
};

this.setIdleIntervalOutsideOfZone(watchFn, this.idle * 1000);
this.setIdleIntervalOutsideOfZone(watchFn, 1000);
}

/*
Expand Down Expand Up @@ -346,7 +346,7 @@ export class Idle implements OnDestroy {
if (this.timeoutVal > 0) {
this.countdown = this.timeoutVal;
this.doCountdown();
this.setTimoutIntervalOutsideZone(() => {
this.setTimeoutIntervalOutsideZone(() => {
this.doCountdownInZone();
}, 1000);
}
Expand All @@ -359,7 +359,7 @@ export class Idle implements OnDestroy {
this.safeClearInterval('idleHandle');
}

private setTimoutIntervalOutsideZone(
private setTimeoutIntervalOutsideZone(
intervalFn: () => void,
frequency: number
) {
Expand Down Expand Up @@ -410,7 +410,9 @@ export class Idle implements OnDestroy {
}

this.onTimeoutWarning.emit(this.countdown);
this.countdown--;

const countdownMs = ((this.timeoutVal - 1) * 1000) + diff;
this.countdown = Math.round(countdownMs / 1000);
}

private safeClearInterval(handleName: string): void {
Expand Down

0 comments on commit 237e7c3

Please sign in to comment.