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

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

Issue 1683233003: Use Stopwatch instead of DateTime to measure elapsed time in tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « tests/lib/async/timer_repeat_test.dart ('k') | tests/standalone/io/sleep_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/timer_test.dart
diff --git a/tests/lib/async/timer_test.dart b/tests/lib/async/timer_test.dart
index fc7ee876b027985a7723f801db38787ca1991054..d08754b862e69d1d0c90f09cbd73fba0ea4063e7 100644
--- a/tests/lib/async/timer_test.dart
+++ b/tests/lib/async/timer_test.dart
@@ -11,7 +11,7 @@ const int STARTTIMEOUT = 1050;
const int DECREASE = 200;
const int ITERATIONS = 5;
-int startTime;
+Stopwatch stopwatch = new Stopwatch();
int timeout;
int iteration;
@@ -21,13 +21,13 @@ int iteration;
int get safetyMargin => identical(1, 1.0) ? 100 : 0;
void timeoutHandler() {
- int endTime = (new DateTime.now()).millisecondsSinceEpoch;
- expect(endTime - startTime + safetyMargin, greaterThanOrEqualTo(timeout));
+ expect(stopwatch.elapsedMilliseconds + safetyMargin,
+ greaterThanOrEqualTo(timeout));
if (iteration < ITERATIONS) {
iteration++;
timeout = timeout - DECREASE;
Duration duration = new Duration(milliseconds: timeout);
- startTime = (new DateTime.now()).millisecondsSinceEpoch;
+ stopwatch.reset();
new Timer(duration, expectAsync(timeoutHandler));
}
}
@@ -37,7 +37,7 @@ main() {
iteration = 0;
timeout = STARTTIMEOUT;
Duration duration = new Duration(milliseconds: timeout);
- startTime = (new DateTime.now()).millisecondsSinceEpoch;
+ stopwatch.start();
new Timer(duration, expectAsync(timeoutHandler));
});
}
« no previous file with comments | « tests/lib/async/timer_repeat_test.dart ('k') | tests/standalone/io/sleep_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698