Chromium Code Reviews| 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..d225ba2680946b5c7ed406ced02176e8587aab90 100644 |
| --- a/tests/lib/async/multiple_timer_test.dart |
| +++ b/tests/lib/async/multiple_timer_test.dart |
| @@ -12,6 +12,9 @@ const Duration TIMEOUT2 = const Duration(seconds: 2); |
| const Duration TIMEOUT3 = const Duration(milliseconds: 500); |
| const Duration TIMEOUT4 = const Duration(milliseconds: 1500); |
| +// Easy way to know if the test is compiled by dart2js. |
| +bool get isCompiledByDart2Js => identical(1, 1.0); |
| + |
|
ricow1
2013/03/19 14:45:12
how about:
bool get timerSafetyMargin => isCompile
floitsch
2013/03/19 14:47:58
Done.
|
| main() { |
| test("multiple timer test", () { |
| Stopwatch _stopwatch1 = new Stopwatch(); |
| @@ -23,8 +26,10 @@ main() { |
| void timeoutHandler1() { |
| // The stopwatch is more precise than the Timer. It can happen that |
| - // the TIMEOUT triggers *slightly* too early. |
| - expect(_stopwatch1.elapsedMilliseconds + 1, |
| + // the TIMEOUT triggers *slightly* too early on the VM. |
| + // In the browser we have seen much worse variations. |
| + int safetyMargin = isCompiledByDart2Js ? 100 : 1; |
| + expect(_stopwatch1.elapsedMilliseconds + safetyMargin, |
| greaterThanOrEqualTo(TIMEOUT1.inMilliseconds)); |
| expect(_order[_message], 0); |
| _message++; |
| @@ -32,8 +37,10 @@ main() { |
| void timeoutHandler2() { |
| // The stopwatch is more precise than the Timer. It can happen that |
| - // the TIMEOUT triggers *slightly* too early. |
| - expect(_stopwatch2.elapsedMilliseconds + 1, |
| + // the TIMEOUT triggers *slightly* too early on the VM. |
| + // In the browser we have seen much worse variations. |
| + int safetyMargin = isCompiledByDart2Js ? 100 : 1; |
| + expect(_stopwatch2.elapsedMilliseconds + safetyMargin, |
| greaterThanOrEqualTo(TIMEOUT2.inMilliseconds)); |
| expect(_order[_message], 1); |
| _message++; |
| @@ -41,8 +48,10 @@ main() { |
| void timeoutHandler3() { |
| // The stopwatch is more precise than the Timer. It can happen that |
| - // the TIMEOUT triggers *slightly* too early. |
| - expect(_stopwatch3.elapsedMilliseconds + 1, |
| + // the TIMEOUT triggers *slightly* too early on the VM. |
| + // In the browser we have seen much worse variations. |
| + int safetyMargin = isCompiledByDart2Js ? 100 : 1; |
| + expect(_stopwatch3.elapsedMilliseconds + safetyMargin, |
| greaterThanOrEqualTo(TIMEOUT3.inMilliseconds)); |
| expect(_order[_message], 2); |
| _message++; |
| @@ -50,8 +59,10 @@ main() { |
| void timeoutHandler4() { |
| // The stopwatch is more precise than the Timer. It can happen that |
| - // the TIMEOUT triggers *slightly* too early. |
| - expect(_stopwatch4.elapsedMilliseconds + 1, |
| + // the TIMEOUT triggers *slightly* too early on the VM. |
| + // In the browser we have seen much worse variations. |
| + int safetyMargin = isCompiledByDart2Js ? 100 : 1; |
| + expect(_stopwatch4.elapsedMilliseconds + safetyMargin, |
| greaterThanOrEqualTo(TIMEOUT4.inMilliseconds)); |
| expect(_order[_message], 3); |
| _message++; |