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