From a7a2f72e1d5ec700cb5bcffb21ee0e5456593a5b Mon Sep 17 00:00:00 2001 From: John Thomas McDole Date: Wed, 24 Feb 2016 22:05:34 -0800 Subject: [PATCH] Non-periodic Timers are not active while executing callback() Copied from google/quiver-dart #282 --- lib/testing/src/fake_async.dart | 2 +- test/testing/fake_async_test.dart | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/testing/src/fake_async.dart b/lib/testing/src/fake_async.dart index b2ce951..34b9977 100644 --- a/lib/testing/src/fake_async.dart +++ b/lib/testing/src/fake_async.dart @@ -248,8 +248,8 @@ class _FakeAsync extends FakeAsync { timer._callback(timer); timer._nextCall += timer._duration; } else { - timer._callback(); _timers.remove(timer); + timer._callback(); } } diff --git a/test/testing/fake_async_test.dart b/test/testing/fake_async_test.dart index 7319f43..882a0fc 100644 --- a/test/testing/fake_async_test.dart +++ b/test/testing/fake_async_test.dart @@ -598,5 +598,27 @@ main() { }); }); }); + + group('timers', () { + test('should behave like real timers', () { + return new FakeAsync().run((async) { + var timeout = const Duration(minutes: 1); + int counter = 0; + var timer; + timer = new Timer(timeout, () { + counter++; + expect(timer.isActive, isFalse, + reason: "is not active while executing callback"); + }); + expect(timer.isActive, isTrue, + reason: "is active before executing callback"); + async.elapse(timeout); + expect(counter, equals(1), reason: "timer executed"); + expect(timer.isActive, isFalse, + reason: "is not active after executing callback"); + }); + }); + ; + }); }); }