From 4b6893369353ac9bb2648259c037fdd33abda0a7 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Thu, 17 May 2018 18:40:32 +1000 Subject: [PATCH 1/2] test(TestScheduler): add failing test --- spec/schedulers/TestScheduler-spec.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/schedulers/TestScheduler-spec.ts b/spec/schedulers/TestScheduler-spec.ts index 848255f358..11daad56a3 100644 --- a/spec/schedulers/TestScheduler-spec.ts +++ b/spec/schedulers/TestScheduler-spec.ts @@ -1,5 +1,6 @@ import { expect } from 'chai'; import { hot, cold, expectObservable, expectSubscriptions, time } from '../helpers/marble-testing'; +import { AsyncScheduler } from 'rxjs/internal/scheduler/AsyncScheduler'; import { TestScheduler } from 'rxjs/testing'; import { Observable, NEVER, EMPTY, Subject, of, concat, merge, Notification } from 'rxjs'; import { delay, debounceTime, concatMap } from 'rxjs/operators'; @@ -441,5 +442,25 @@ describe('TestScheduler', () => { done(); }); }); + + it('should restore changes upon thrown errors', () => { + const testScheduler = new TestScheduler(assertDeepEquals); + + const frameTimeFactor = TestScheduler['frameTimeFactor']; + const maxFrames = testScheduler.maxFrames; + const runMode = testScheduler['runMode']; + const delegate = AsyncScheduler.delegate; + + try { + testScheduler.run(() => { + throw new Error('kaboom!'); + }); + } catch { /* empty */ } + + expect(TestScheduler['frameTimeFactor']).to.equal(frameTimeFactor); + expect(testScheduler.maxFrames).to.equal(maxFrames); + expect(testScheduler['runMode']).to.equal(runMode); + expect(AsyncScheduler.delegate).to.equal(delegate); + }); }); }); From 27cb9b60a3399955c8df1405090b81d22be4315e Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Thu, 17 May 2018 18:41:10 +1000 Subject: [PATCH 2/2] fix(TestScheduler): restore run changes upon error --- src/internal/testing/TestScheduler.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/internal/testing/TestScheduler.ts b/src/internal/testing/TestScheduler.ts index 329b3f3319..60474b3078 100644 --- a/src/internal/testing/TestScheduler.ts +++ b/src/internal/testing/TestScheduler.ts @@ -378,14 +378,15 @@ export class TestScheduler extends VirtualTimeScheduler { expectObservable: this.expectObservable.bind(this), expectSubscriptions: this.expectSubscriptions.bind(this), }; - const ret = callback(helpers); - this.flush(); - - TestScheduler.frameTimeFactor = prevFrameTimeFactor; - this.maxFrames = prevMaxFrames; - this.runMode = false; - AsyncScheduler.delegate = undefined; - - return ret; + try { + const ret = callback(helpers); + this.flush(); + return ret; + } finally { + TestScheduler.frameTimeFactor = prevFrameTimeFactor; + this.maxFrames = prevMaxFrames; + this.runMode = false; + AsyncScheduler.delegate = undefined; + } } }