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

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

Issue 60013013: Make catch_errors13_test non-flaky. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Slight comment change. Created 7 years, 1 month 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/catch_errors13_test.dart
diff --git a/tests/lib/async/catch_errors13_test.dart b/tests/lib/async/catch_errors13_test.dart
index 0889f2e19340878fa3facd825b97276f41e74842..1723f87d1e264b450ff52ad2bf832b96f63746ff 100644
--- a/tests/lib/async/catch_errors13_test.dart
+++ b/tests/lib/async/catch_errors13_test.dart
@@ -19,16 +19,36 @@ main() {
// Test that errors are caught by nested `catchErrors`. Also uses
// `scheduleMicrotask` in the body of a Timer.
+ bool outerTimerRan = false;
+ int outerTimerCounterDelayCount = 0;
catchErrors(() {
events.add("catch error entry");
catchErrors(() {
events.add("catch error entry2");
Timer.run(() { throw "timer error"; });
- new Timer(const Duration(milliseconds: 50),
- () {
- scheduleMicrotask(() { throw "scheduleMicrotask"; });
- throw "delayed error";
- });
+
+ // We want this timer to run after the timer below. When the machine is
+ // slow we saw that the timer below was scheduled more than 50ms after
+ // this line. A duration of 50ms was therefore not enough to guarantee
+ // that this timer runs before the timer below.
+ // Instead of increasing the duration to a bigger amount we decided to
+ // verify that the other timer already ran, and reschedule if not.
+ // This way we could reduce the timeout (to 10ms now), while still
+ // allowing for more time, in case the machine is slow.
+ void runDelayed() {
+ new Timer(const Duration(milliseconds: 10),
+ () {
+ if (outerTimerRan) {
+ scheduleMicrotask(() { throw "scheduleMicrotask"; });
+ throw "delayed error";
+ } else if (outerTimerCounterDelayCount < 100) {
+ outerTimerCounterDelayCount++;
+ runDelayed();
+ }
+ });
+ }
+
+ runDelayed();
}).listen((x) {
events.add(x);
if (x == "scheduleMicrotask") {
@@ -36,7 +56,10 @@ main() {
}
});
events.add("after inner");
- Timer.run(() { throw "timer outer"; });
+ Timer.run(() {
+ outerTimerRan = true;
+ throw "timer outer";
+ });
throw "inner throw";
}).listen((x) {
events.add(x);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698