Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: tests/lib/async/timer_regress22626_test.dart

Issue 2075793002: Make timer test more robust. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698