c92af46433
Bug: https://github.com/dart-lang/sdk/issues/36900 Change-Id: I1306b2df7c789597e49d2033b660a3ea62d6c1a4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104525 Commit-Queue: Todd Volkert <tvolkert@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
65 lines
1.8 KiB
Dart
65 lines
1.8 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
//
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import "package:expect/expect.dart";
|
|
|
|
const int NUM_SERVERS = 10;
|
|
|
|
void main(List<String> args) {
|
|
if (args.isEmpty) {
|
|
for (int i = 0; i < NUM_SERVERS; ++i) {
|
|
makeServer().then((server) {
|
|
runClientProcess(server.port).then((_) => server.close());
|
|
});
|
|
}
|
|
} else if (args[0] == '--client') {
|
|
int port = int.parse(args[1]);
|
|
runClient(port);
|
|
} else {
|
|
Expect.fail('Unknown arguments to http_cross_process_test.dart');
|
|
}
|
|
}
|
|
|
|
Future makeServer() {
|
|
return HttpServer.bind(InternetAddress.loopbackIPv4, 0).then((server) {
|
|
server.listen((request) {
|
|
request.cast<List<int>>().pipe(request.response);
|
|
});
|
|
return server;
|
|
});
|
|
}
|
|
|
|
Future runClientProcess(int port) {
|
|
return Process.run(
|
|
Platform.executable,
|
|
[]
|
|
..addAll(Platform.executableArguments)
|
|
..add(Platform.script.toFilePath())
|
|
..add('--client')
|
|
..add(port.toString()))
|
|
.then((ProcessResult result) {
|
|
if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) {
|
|
print("Client failed, exit code ${result.exitCode}");
|
|
print(" stdout:");
|
|
print(result.stdout);
|
|
print(" stderr:");
|
|
print(result.stderr);
|
|
Expect.fail('Client subprocess exit code: ${result.exitCode}');
|
|
}
|
|
});
|
|
}
|
|
|
|
runClient(int port) {
|
|
var client = new HttpClient();
|
|
client
|
|
.get('127.0.0.1', port, "/")
|
|
.then((request) => request.close())
|
|
.then((response) => response.drain())
|
|
.then((_) => client.close())
|
|
.then((_) => print('SUCCESS'));
|
|
}
|