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

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

Issue 3003853002: Add ticks counter to Timer. (Closed)
Patch Set: Test that tick increments by more than one 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 import 'dart:async';
6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart';
8
9 const ms = const Duration(milliseconds: 1);
10
11 expectGTE(min, actual, msg) {
12 if (actual >= min) return;
13 Expect._fail(msg.replaceAll('{0}', "$min").replaceAll('{1}', "$actual"));
14 }
15
16 main() {
17 int interval = 20;
18 asyncStart();
19 var sw = new Stopwatch()..start();
20 int nextTick = 1;
21 new Timer.periodic(ms * interval, (t) {
22 expectGTE(nextTick, t.tick, "tick {1} before expect next tick {0}.");
23 nextTick = t.tick + 1; // Always increment tick by at least one.
24 int time = sw.elapsedMilliseconds;
25 int minTime = interval * t.tick;
26 expectGTE(minTime, time, "Actual time {1} before {0} at tick ${t.tick}");
27 if (t.tick > 20) {
28 t.cancel();
29 asyncEnd();
30 }
31 });
32 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698