OLD | NEW |
---|---|
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 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 /// | 137 /// |
138 /// Unlike [pubServe], this doesn't determine the port number of the server, and | 138 /// Unlike [pubServe], this doesn't determine the port number of the server, and |
139 /// so may be used to test for errors in the initialization process. | 139 /// so may be used to test for errors in the initialization process. |
140 /// | 140 /// |
141 /// Returns the `pub serve` process. | 141 /// Returns the `pub serve` process. |
142 ScheduledProcess startPubServe({Iterable<String> args, | 142 ScheduledProcess startPubServe({Iterable<String> args, |
143 bool createWebDir: true}) { | 143 bool createWebDir: true}) { |
144 var pubArgs = [ | 144 var pubArgs = [ |
145 "serve", | 145 "serve", |
146 "--port=0", // Use port 0 to get an ephemeral port. | 146 "--port=0", // Use port 0 to get an ephemeral port. |
147 "--hostname=127.0.0.1", // Force IPv4 on bots. | 147 "--hostname=localhost", // Force IPv4 on bots. |
Bob Nystrom
2014/06/06 20:22:03
This can just be removed now, right?
nweiz
2014/06/09 20:01:19
Done.
| |
148 "--force-poll", | 148 "--force-poll", |
149 "--log-admin-url" | 149 "--log-admin-url" |
150 ]; | 150 ]; |
151 | 151 |
152 if (args != null) pubArgs.addAll(args); | 152 if (args != null) pubArgs.addAll(args); |
153 | 153 |
154 // Dart2js can take a long time to compile dart code, so we increase the | 154 // Dart2js can take a long time to compile dart code, so we increase the |
155 // timeout to cope with that. | 155 // timeout to cope with that. |
156 currentSchedule.timeout *= 1.5; | 156 currentSchedule.timeout *= 1.5; |
157 | 157 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 schedule(() { | 199 schedule(() { |
200 expect(_ports, isNot(isEmpty)); | 200 expect(_ports, isNot(isEmpty)); |
201 _portsCompleter.complete(); | 201 _portsCompleter.complete(); |
202 }); | 202 }); |
203 | 203 |
204 return _pubServer; | 204 return _pubServer; |
205 } | 205 } |
206 | 206 |
207 /// The regular expression for parsing pub's output line describing the URL for | 207 /// The regular expression for parsing pub's output line describing the URL for |
208 /// the server. | 208 /// the server. |
209 final _parsePortRegExp = new RegExp(r"([^ ]+) +on http://127\.0\.0\.1:(\d+)"); | 209 final _parsePortRegExp = new RegExp(r"([^ ]+) +on http://localhost:(\d+)"); |
210 | 210 |
211 /// Parses the port number from the "Running admin server on 127.0.0.1:1234" | 211 /// Parses the port number from the "Running admin server on localhost:1234" |
212 /// line printed by pub serve. | 212 /// line printed by pub serve. |
213 bool _parseAdminPort(String line) { | 213 bool _parseAdminPort(String line) { |
214 var match = _parsePortRegExp.firstMatch(line); | 214 var match = _parsePortRegExp.firstMatch(line); |
215 if (match == null) return false; | 215 if (match == null) return false; |
216 _adminPort = int.parse(match[2]); | 216 _adminPort = int.parse(match[2]); |
217 return true; | 217 return true; |
218 } | 218 } |
219 | 219 |
220 /// Parses the port number from the "Serving blah on 127.0.0.1:1234" line | 220 /// Parses the port number from the "Serving blah on localhost:1234" line |
221 /// printed by pub serve. | 221 /// printed by pub serve. |
222 bool _parsePort(String line) { | 222 bool _parsePort(String line) { |
223 var match = _parsePortRegExp.firstMatch(line); | 223 var match = _parsePortRegExp.firstMatch(line); |
224 if (match == null) return false; | 224 if (match == null) return false; |
225 _ports[match[1]] = int.parse(match[2]); | 225 _ports[match[1]] = int.parse(match[2]); |
226 return true; | 226 return true; |
227 } | 227 } |
228 | 228 |
229 void endPubServe() { | 229 void endPubServe() { |
230 _pubServer.kill(); | 230 _pubServer.kill(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 /// Schedules opening a web socket connection to the currently running pub | 315 /// Schedules opening a web socket connection to the currently running pub |
316 /// serve. | 316 /// serve. |
317 Future _ensureWebSocket() { | 317 Future _ensureWebSocket() { |
318 // Use the existing one if already connected. | 318 // Use the existing one if already connected. |
319 if (_webSocket != null) return new Future.value(); | 319 if (_webSocket != null) return new Future.value(); |
320 | 320 |
321 // Server should already be running. | 321 // Server should already be running. |
322 expect(_pubServer, isNotNull); | 322 expect(_pubServer, isNotNull); |
323 expect(_adminPort, isNotNull); | 323 expect(_adminPort, isNotNull); |
324 | 324 |
325 return WebSocket.connect("ws://127.0.0.1:$_adminPort").then((socket) { | 325 return WebSocket.connect("ws://localhost:$_adminPort").then((socket) { |
326 _webSocket = socket; | 326 _webSocket = socket; |
327 // TODO(rnystrom): Works around #13913. | 327 // TODO(rnystrom): Works around #13913. |
328 _webSocketBroadcastStream = _webSocket.map(JSON.decode).asBroadcastStream(); | 328 _webSocketBroadcastStream = _webSocket.map(JSON.decode).asBroadcastStream(); |
329 }); | 329 }); |
330 } | 330 } |
331 | 331 |
332 /// Schedules closing the web socket connection to the currently-running pub | 332 /// Schedules closing the web socket connection to the currently-running pub |
333 /// serve. | 333 /// serve. |
334 Future closeWebSocket() { | 334 Future closeWebSocket() { |
335 schedule(() { | 335 schedule(() { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 } | 473 } |
474 | 474 |
475 /// Returns a URL string for the server serving [path] from [root]. | 475 /// Returns a URL string for the server serving [path] from [root]. |
476 /// | 476 /// |
477 /// If [root] is omitted, defaults to "web". If [path] is omitted, no path is | 477 /// If [root] is omitted, defaults to "web". If [path] is omitted, no path is |
478 /// included. Unlike [getServerUrl], this should only be called after the ports | 478 /// included. Unlike [getServerUrl], this should only be called after the ports |
479 /// are known. | 479 /// are known. |
480 String _getServerUrlSync([String root, String path]) { | 480 String _getServerUrlSync([String root, String path]) { |
481 if (root == null) root = 'web'; | 481 if (root == null) root = 'web'; |
482 expect(_ports, contains(root)); | 482 expect(_ports, contains(root)); |
483 var url = "http://127.0.0.1:${_ports[root]}"; | 483 var url = "http://localhost:${_ports[root]}"; |
484 if (path != null) url = "$url/$path"; | 484 if (path != null) url = "$url/$path"; |
485 return url; | 485 return url; |
486 } | 486 } |
487 | 487 |
OLD | NEW |