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

Unified Diff: tests/lib/async/multiple_timer_test.dart

Issue 12855003: Add safetymargin for timer tests in browsers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/async/timer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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++;
« no previous file with comments | « no previous file | tests/lib/async/timer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698