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

Side by Side Diff: sdk/lib/_internal/pub/test/serve/utils.dart

Issue 22986002: Add file watching to pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move some code around. Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 pub_tests; 5 library pub_tests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:scheduled_test/scheduled_process.dart'; 10 import 'package:scheduled_test/scheduled_process.dart';
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 /// Schedules an HTTP request to the running pub server with [urlPath] and 62 /// Schedules an HTTP request to the running pub server with [urlPath] and
63 /// verifies that it responds with a 404. 63 /// verifies that it responds with a 404.
64 void requestShould404(String urlPath) { 64 void requestShould404(String urlPath) {
65 schedule(() { 65 schedule(() {
66 return http.get("http://localhost:$_port/$urlPath").then((response) { 66 return http.get("http://localhost:$_port/$urlPath").then((response) {
67 expect(response.statusCode, equals(404)); 67 expect(response.statusCode, equals(404));
68 }); 68 });
69 }, "request $urlPath"); 69 }, "request $urlPath");
70 }
71
72 /// Reads lines from pub serve's stdout until it prints the build success
73 /// message.
74 ///
75 /// The schedule will not proceed until the output is found. If not found, it
76 /// will eventually time out.
77 void waitForBuildSuccess() {
78 nextLine() {
79 return _pubServer.nextLine().then((line) {
80 if (line.contains("successfully")) return;
81
82 // This line wasn't it, so ignore it and keep trying.
83 return nextLine();
84 });
85 }
86
87 schedule(nextLine);
88 }
89
90 /// Returns a [Future] that completes after pumping the event queue [times]
91 /// times. By default, this should pump the event queue enough times to allow
92 /// any code to run, as long as it's not waiting on some external event.
93 Future _pumpEventQueue([int times=20]) {
94 if (times == 0) return new Future.value();
95 // We use a delayed future to allow runAsync events to finish. The
96 // Future.value or Future() constructors use runAsync themselves and would
97 // therefore not wait for runAsync callbacks that are scheduled after invoking
98 // this method.
99 return new Future.delayed(Duration.ZERO, () => _pumpEventQueue(times - 1));
70 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698