Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d32e79b

Browse files
authored
fix: make fakeAsync test spec timer id global (#1207)
There is a possibility that a single test gets timer id-s from two separate fakeAsync test zones and the id-s could clash. This changes makes it such that the next timer id is global and the can never clash.
1 parent 2a8415d commit d32e79b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/zone-spec/fake-async-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const timers = {
6464

6565
class Scheduler {
6666
// Next scheduler id.
67-
public nextId: number = 1;
67+
public static nextId: number = 1;
6868

6969
// Scheduler queue with the tuple of end time and callback function - sorted by end time.
7070
private _schedulerQueue: ScheduledFunction[] = [];
@@ -90,7 +90,7 @@ class Scheduler {
9090
scheduleFunction(
9191
cb: Function, delay: number, args: any[] = [], isPeriodic: boolean = false,
9292
isRequestAnimationFrame: boolean = false, id: number = -1): number {
93-
let currentId: number = id < 0 ? this.nextId++ : id;
93+
let currentId: number = id < 0 ? Scheduler.nextId++ : id;
9494
let endTime = this._currentTime + delay;
9595

9696
// Insert so that scheduler queue remains sorted by end time.
@@ -292,7 +292,7 @@ class FakeAsyncTestZoneSpec implements ZoneSpec {
292292
}
293293

294294
private _setTimeout(fn: Function, delay: number, args: any[], isTimer = true): number {
295-
let removeTimerFn = this._dequeueTimer(this._scheduler.nextId);
295+
let removeTimerFn = this._dequeueTimer(Scheduler.nextId);
296296
// Queue the callback and dequeue the timer on success and error.
297297
let cb = this._fnAndFlush(fn, {onSuccess: removeTimerFn, onError: removeTimerFn});
298298
let id = this._scheduler.scheduleFunction(cb, delay, args, false, !isTimer);
@@ -308,7 +308,7 @@ class FakeAsyncTestZoneSpec implements ZoneSpec {
308308
}
309309

310310
private _setInterval(fn: Function, interval: number, args: any[]): number {
311-
let id = this._scheduler.nextId;
311+
let id = Scheduler.nextId;
312312
let completers = {onSuccess: null as any, onError: this._dequeuePeriodicTimer(id)};
313313
let cb = this._fnAndFlush(fn, completers);
314314

0 commit comments

Comments
 (0)