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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/async/timer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library multiple_timer_test; 5 library multiple_timer_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import '../../../pkg/unittest/lib/unittest.dart'; 8 import '../../../pkg/unittest/lib/unittest.dart';
9 9
10 const Duration TIMEOUT1 = const Duration(seconds: 1); 10 const Duration TIMEOUT1 = const Duration(seconds: 1);
11 const Duration TIMEOUT2 = const Duration(seconds: 2); 11 const Duration TIMEOUT2 = const Duration(seconds: 2);
12 const Duration TIMEOUT3 = const Duration(milliseconds: 500); 12 const Duration TIMEOUT3 = const Duration(milliseconds: 500);
13 const Duration TIMEOUT4 = const Duration(milliseconds: 1500); 13 const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
14 14
15 // Easy way to know if the test is compiled by dart2js.
16 bool get isCompiledByDart2Js => identical(1, 1.0);
17
ricow1 2013/03/19 14:45:12 how about: bool get timerSafetyMargin => isCompile
floitsch 2013/03/19 14:47:58 Done.
15 main() { 18 main() {
16 test("multiple timer test", () { 19 test("multiple timer test", () {
17 Stopwatch _stopwatch1 = new Stopwatch(); 20 Stopwatch _stopwatch1 = new Stopwatch();
18 Stopwatch _stopwatch2 = new Stopwatch(); 21 Stopwatch _stopwatch2 = new Stopwatch();
19 Stopwatch _stopwatch3 = new Stopwatch(); 22 Stopwatch _stopwatch3 = new Stopwatch();
20 Stopwatch _stopwatch4 = new Stopwatch(); 23 Stopwatch _stopwatch4 = new Stopwatch();
21 List<int> _order; 24 List<int> _order;
22 int _message; 25 int _message;
23 26
24 void timeoutHandler1() { 27 void timeoutHandler1() {
25 // The stopwatch is more precise than the Timer. It can happen that 28 // The stopwatch is more precise than the Timer. It can happen that
26 // the TIMEOUT triggers *slightly* too early. 29 // the TIMEOUT triggers *slightly* too early on the VM.
27 expect(_stopwatch1.elapsedMilliseconds + 1, 30 // In the browser we have seen much worse variations.
31 int safetyMargin = isCompiledByDart2Js ? 100 : 1;
32 expect(_stopwatch1.elapsedMilliseconds + safetyMargin,
28 greaterThanOrEqualTo(TIMEOUT1.inMilliseconds)); 33 greaterThanOrEqualTo(TIMEOUT1.inMilliseconds));
29 expect(_order[_message], 0); 34 expect(_order[_message], 0);
30 _message++; 35 _message++;
31 } 36 }
32 37
33 void timeoutHandler2() { 38 void timeoutHandler2() {
34 // The stopwatch is more precise than the Timer. It can happen that 39 // The stopwatch is more precise than the Timer. It can happen that
35 // the TIMEOUT triggers *slightly* too early. 40 // the TIMEOUT triggers *slightly* too early on the VM.
36 expect(_stopwatch2.elapsedMilliseconds + 1, 41 // In the browser we have seen much worse variations.
42 int safetyMargin = isCompiledByDart2Js ? 100 : 1;
43 expect(_stopwatch2.elapsedMilliseconds + safetyMargin,
37 greaterThanOrEqualTo(TIMEOUT2.inMilliseconds)); 44 greaterThanOrEqualTo(TIMEOUT2.inMilliseconds));
38 expect(_order[_message], 1); 45 expect(_order[_message], 1);
39 _message++; 46 _message++;
40 } 47 }
41 48
42 void timeoutHandler3() { 49 void timeoutHandler3() {
43 // The stopwatch is more precise than the Timer. It can happen that 50 // The stopwatch is more precise than the Timer. It can happen that
44 // the TIMEOUT triggers *slightly* too early. 51 // the TIMEOUT triggers *slightly* too early on the VM.
45 expect(_stopwatch3.elapsedMilliseconds + 1, 52 // In the browser we have seen much worse variations.
53 int safetyMargin = isCompiledByDart2Js ? 100 : 1;
54 expect(_stopwatch3.elapsedMilliseconds + safetyMargin,
46 greaterThanOrEqualTo(TIMEOUT3.inMilliseconds)); 55 greaterThanOrEqualTo(TIMEOUT3.inMilliseconds));
47 expect(_order[_message], 2); 56 expect(_order[_message], 2);
48 _message++; 57 _message++;
49 } 58 }
50 59
51 void timeoutHandler4() { 60 void timeoutHandler4() {
52 // The stopwatch is more precise than the Timer. It can happen that 61 // The stopwatch is more precise than the Timer. It can happen that
53 // the TIMEOUT triggers *slightly* too early. 62 // the TIMEOUT triggers *slightly* too early on the VM.
54 expect(_stopwatch4.elapsedMilliseconds + 1, 63 // In the browser we have seen much worse variations.
64 int safetyMargin = isCompiledByDart2Js ? 100 : 1;
65 expect(_stopwatch4.elapsedMilliseconds + safetyMargin,
55 greaterThanOrEqualTo(TIMEOUT4.inMilliseconds)); 66 greaterThanOrEqualTo(TIMEOUT4.inMilliseconds));
56 expect(_order[_message], 3); 67 expect(_order[_message], 3);
57 _message++; 68 _message++;
58 } 69 }
59 70
60 _order = new List<int>(4); 71 _order = new List<int>(4);
61 _order[0] = 2; 72 _order[0] = 2;
62 _order[1] = 0; 73 _order[1] = 0;
63 _order[2] = 3; 74 _order[2] = 3;
64 _order[3] = 1; 75 _order[3] = 1;
65 _message = 0; 76 _message = 0;
66 77
67 _stopwatch1.start(); 78 _stopwatch1.start();
68 new Timer(TIMEOUT1, expectAsync0(timeoutHandler1)); 79 new Timer(TIMEOUT1, expectAsync0(timeoutHandler1));
69 _stopwatch2.start(); 80 _stopwatch2.start();
70 new Timer(TIMEOUT2, expectAsync0(timeoutHandler2)); 81 new Timer(TIMEOUT2, expectAsync0(timeoutHandler2));
71 _stopwatch3.start(); 82 _stopwatch3.start();
72 new Timer(TIMEOUT3, expectAsync0(timeoutHandler3)); 83 new Timer(TIMEOUT3, expectAsync0(timeoutHandler3));
73 _stopwatch4.start(); 84 _stopwatch4.start();
74 new Timer(TIMEOUT4, expectAsync0(timeoutHandler4)); 85 new Timer(TIMEOUT4, expectAsync0(timeoutHandler4));
75 }); 86 });
76 } 87 }
OLDNEW
« 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