OLD | NEW |
(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 } |
OLD | NEW |