Index: sdk/lib/_internal/pub/test/serve/utils.dart |
diff --git a/sdk/lib/_internal/pub/test/serve/utils.dart b/sdk/lib/_internal/pub/test/serve/utils.dart |
index 3a083923e61868e62a4dec541b797e4aea32cc01..0e11129aa783dae104acce27b1f7f50cb907313e 100644 |
--- a/sdk/lib/_internal/pub/test/serve/utils.dart |
+++ b/sdk/lib/_internal/pub/test/serve/utils.dart |
@@ -67,4 +67,38 @@ void requestShould404(String urlPath) { |
expect(response.statusCode, equals(404)); |
}); |
}, "request $urlPath"); |
+} |
+ |
+/// Reads lines from pub serve's stdout until one equal to [output] is found. |
+/// |
+/// The schedule will not proceed until the desired output is found. If not |
+/// found, it will eventually time out. |
+void waitForOutput(String output) { |
+ findMatchingLine() { |
+ return _pubServer.nextLine().then((line) { |
+ if (line == output) return true; |
+ |
+ // This line wasn't it, so ignore it and keep trying. |
+ return findMatchingLine(); |
+ }); |
+ } |
+ |
+ expect(findMatchingLine(), completion(isTrue)); |
+} |
+ |
+/// Schedules pumping the event queue. |
+void pumpEventQueue() { |
+ schedule(() => _pumpEventQueue()); |
+} |
+ |
+/// Returns a [Future] that completes after pumping the event queue [times] |
+/// times. By default, this should pump the event queue enough times to allow |
+/// any code to run, as long as it's not waiting on some external event. |
+Future _pumpEventQueue([int times=20]) { |
+ if (times == 0) return new Future.value(); |
+ // We use a delayed future to allow runAsync events to finish. The |
+ // Future.value or Future() constructors use runAsync themselves and would |
+ // therefore not wait for runAsync callbacks that are scheduled after invoking |
+ // this method. |
+ return new Future.delayed(Duration.ZERO, () => _pumpEventQueue(times - 1)); |
} |