Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // | |
| 5 | |
| 6 import "package:expect/expect.dart"; | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 const int NUM_SERVERS = 10; | |
| 11 | |
| 12 void main() { | |
| 13 var args = new Options().arguments; | |
| 14 if (args.isEmpty) { | |
| 15 for (int i = 0; i < NUM_SERVERS; ++i) { | |
| 16 makeServer().then((server) { | |
| 17 runClientProcess(server.port).then((_) => server.close()); | |
| 18 }); | |
| 19 } | |
| 20 } else if (args[0] == 'client') { | |
| 21 int port = int.parse(args[1]); | |
| 22 runClient(port); | |
| 23 } else { | |
| 24 Expect.fail('Unknown arguments to http_cross_process_test.dart'); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 Future makeServer() { | |
| 29 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { | |
| 30 server.listen((request) { | |
| 31 request.pipe(request.response); | |
| 32 }); | |
| 33 return server; | |
| 34 }); | |
| 35 } | |
| 36 | |
| 37 Future runClientProcess(int port) { | |
| 38 return Process.run(Platform.executable, | |
| 39 []..addAll(Platform.executableArguments) | |
| 40 ..add(Platform.script) | |
| 41 ..add('client') | |
|
Søren Gjesse
2013/08/26 09:25:58
Should it be --client ? (for all tests)
| |
| 42 ..add(port.toString())).then((ProcessResult result) { | |
| 43 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { | |
| 44 print("Client failed, exit code ${result.exitCode}"); | |
| 45 print(" stdout:"); | |
| 46 print(result.stdout); | |
| 47 print(" stderr:"); | |
| 48 print(result.stderr); | |
| 49 Expect.fail('Client subprocess exit code: ${result.exitCode}'); | |
| 50 } | |
| 51 }); | |
| 52 } | |
| 53 | |
| 54 runClient(int port) { | |
| 55 var client = new HttpClient(); | |
| 56 client.get(InternetAddress.LOOPBACK_IP_V4, port, "/") | |
| 57 .then((request) => request.close()) | |
| 58 .then((response) => response.listen((data) {}, | |
| 59 onDone: () => print('SUCCESS'))); | |
| 60 } | |
| OLD | NEW |