| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Test that no wakeups are being dropped if we cancel timers. | 5 // Test that no wakeups are being dropped if we cancel timers. |
| 6 // WARNING: For this test to work it cannot rely on any other async features | 6 // WARNING: For this test to work it cannot rely on any other async features |
| 7 // and will just timeout if it is failing. | 7 // and will just timeout if it is failing. |
| 8 | 8 |
| 9 library timer_regress22626_test; | 9 library timer_regress22626_test; |
| 10 | 10 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 import 'dart:math'; | 12 import 'dart:math'; |
| 13 import 'package:expect/expect.dart'; | 13 import 'package:expect/expect.dart'; |
| 14 | 14 |
| 15 int countdown = 10; | 15 int countdown = 5; |
| 16 var rng = new Random(1234); | 16 var rng = new Random(1234); |
| 17 | 17 |
| 18 void test(int delay, int delta) { | 18 void test(int delay, int delta) { |
| 19 var t0 = new Timer(new Duration(milliseconds: delay + delta), | 19 var t0 = new Timer(new Duration(milliseconds: delay + delta), |
| 20 () => Expect.fail("should have been cancelled by now")); | 20 () => Expect.fail("should have been cancelled by now")); |
| 21 new Timer(Duration.ZERO, () => t0.cancel()); | 21 new Timer(Duration.ZERO, () => t0.cancel()); |
| 22 new Timer(Duration.ZERO, | 22 new Timer(Duration.ZERO, |
| 23 () => new Timer(new Duration(milliseconds: delay), | 23 () => new Timer(new Duration(milliseconds: delay), |
| 24 () { | 24 () { |
| 25 if (--countdown == 0) { | 25 if (--countdown == 0) { |
| 26 print("done"); | 26 print("done"); |
| 27 } else { | 27 } else { |
| 28 test(delay, max(0, delta + rng.nextInt(2) - 1)); | 28 test(delay, max(0, delta + rng.nextInt(2) - 1)); |
| 29 } | 29 } |
| 30 })); | 30 })); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void main() { | 33 void main() { |
| 34 test(50, 2); | 34 test(200, 2); |
| 35 } | 35 } |
| OLD | NEW |