Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
|
koda
2015/03/03 18:58:51
2011 -> 2015
Ivan Posva
2015/03/03 19:14:18
Done.
| |
| 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. | |
| 4 | |
| 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 | |
| 7 // and will just timeout if it is failing. | |
| 8 | |
| 9 library timer_regress22626_test; | |
| 10 | |
| 11 import 'dart:async'; | |
| 12 import 'dart:math'; | |
| 13 import 'package:expect/expect.dart'; | |
| 14 | |
| 15 int countdown = 10; | |
| 16 var rng = new Random(1234); | |
| 17 | |
| 18 void test(int delay, int delta) { | |
| 19 var t0 = new Timer(new Duration(milliseconds: delay + delta), | |
| 20 () => Expect.fail("should have been cancelled by now")); | |
| 21 new Timer(Duration.ZERO, () => t0.cancel()); | |
| 22 new Timer(Duration.ZERO, | |
| 23 () => new Timer(new Duration(milliseconds: delay), | |
| 24 () { | |
| 25 if (--countdown == 0) { | |
| 26 print("done"); | |
| 27 } else { | |
| 28 test(delay, max(0, delta + rng.nextInt(2) - 1)); | |
| 29 } | |
| 30 })); | |
| 31 } | |
| 32 | |
| 33 void main() { | |
| 34 test(50, 2); | |
| 35 } | |
| OLD | NEW |