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

Side by Side Diff: tests/lib_2/async/periodic_timer3_test.dart

Issue 3011503002: Revert "Add ticks counter to Timer." (Closed)
Patch Set: Created 3 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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 library timer_test;
6
7 import 'dart:async';
8 import 'package:expect/expect.dart';
9 import 'package:async_helper/async_helper.dart';
10
11 const ms = const Duration(milliseconds: 1);
12
13 expectGTE(min, actual, msg) {
14 if (actual >= min) return;
15 Expect._fail(msg.replaceAll('{0}', "$min").replaceAll('{1}', "$actual"));
16 }
17
18 main() {
19 int interval = 20;
20 asyncStart();
21 var sw = new Stopwatch()..start();
22 int nextTick = 1;
23 new Timer.periodic(ms * interval, (t) {
24 expectGTE(nextTick, t.tick, "tick {1} before expect next tick {0}.");
25 int time = sw.elapsedMilliseconds;
26 int minTime = interval * t.tick;
27 expectGTE(minTime, time, "Actual time {1} before {0} at tick ${t.tick}");
28 while (sw.elapsedMilliseconds < time + 3 * interval) {
29 // idle.
30 }
31 nextTick = t.tick + 2; // At least increment by two, probably more.
32 if (t.tick > 20) {
33 t.cancel();
34 asyncEnd();
35 }
36 });
37 }
OLDNEW
« no previous file with comments | « tests/lib_2/async/periodic_timer2_test.dart ('k') | tests/lib_2/async/periodic_timer4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698