| Index: tests/lib/async/multiple_timer_test.dart
|
| diff --git a/tests/lib/async/multiple_timer_test.dart b/tests/lib/async/multiple_timer_test.dart
|
| index 836e5fcb782519281901e09e61f4115e3bf4b8f8..824ced6b0270c2e469ab80dd59dadcb2ddbc583b 100644
|
| --- a/tests/lib/async/multiple_timer_test.dart
|
| +++ b/tests/lib/async/multiple_timer_test.dart
|
| @@ -12,6 +12,14 @@ const Duration TIMEOUT2 = const Duration(seconds: 2);
|
| const Duration TIMEOUT3 = const Duration(milliseconds: 500);
|
| const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
|
|
|
| +// The stopwatch is more precise than the Timer. It can happen that
|
| +// the TIMEOUT triggers *slightly* too early on the VM. So we add a millisecond
|
| +// as safetymargin.
|
| +// Some browsers (Firefox and IE so far) can trigger too early. So we add more
|
| +// margin. We use identical(1, 1.0) as an easy way to know if the test is
|
| +// compiled by dart2js.
|
| +int get safetyMargin => identical(1, 1.0) ? 1 : 100;
|
| +
|
| main() {
|
| test("multiple timer test", () {
|
| Stopwatch _stopwatch1 = new Stopwatch();
|
| @@ -22,36 +30,28 @@ main() {
|
| int _message;
|
|
|
| void timeoutHandler1() {
|
| - // The stopwatch is more precise than the Timer. It can happen that
|
| - // the TIMEOUT triggers *slightly* too early.
|
| - expect(_stopwatch1.elapsedMilliseconds + 1,
|
| + expect(_stopwatch1.elapsedMilliseconds + safetyMargin,
|
| greaterThanOrEqualTo(TIMEOUT1.inMilliseconds));
|
| expect(_order[_message], 0);
|
| _message++;
|
| }
|
|
|
| void timeoutHandler2() {
|
| - // The stopwatch is more precise than the Timer. It can happen that
|
| - // the TIMEOUT triggers *slightly* too early.
|
| - expect(_stopwatch2.elapsedMilliseconds + 1,
|
| + expect(_stopwatch2.elapsedMilliseconds + safetyMargin,
|
| greaterThanOrEqualTo(TIMEOUT2.inMilliseconds));
|
| expect(_order[_message], 1);
|
| _message++;
|
| }
|
|
|
| void timeoutHandler3() {
|
| - // The stopwatch is more precise than the Timer. It can happen that
|
| - // the TIMEOUT triggers *slightly* too early.
|
| - expect(_stopwatch3.elapsedMilliseconds + 1,
|
| + expect(_stopwatch3.elapsedMilliseconds + safetyMargin,
|
| greaterThanOrEqualTo(TIMEOUT3.inMilliseconds));
|
| expect(_order[_message], 2);
|
| _message++;
|
| }
|
|
|
| void timeoutHandler4() {
|
| - // The stopwatch is more precise than the Timer. It can happen that
|
| - // the TIMEOUT triggers *slightly* too early.
|
| - expect(_stopwatch4.elapsedMilliseconds + 1,
|
| + expect(_stopwatch4.elapsedMilliseconds + safetyMargin,
|
| greaterThanOrEqualTo(TIMEOUT4.inMilliseconds));
|
| expect(_order[_message], 3);
|
| _message++;
|
|
|