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

Side by Side Diff: tests/standalone/io/socket_cross_process_test.dart

Issue 23414004: Add dart:io tests for creating a client and server in separate processes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
(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 socket_cross_process_test.dart');
25 }
26 }
27
28 Future makeServer() {
29 return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) {
30 server.listen((request) {
31 request.pipe(request);
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')
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 Socket.connect(InternetAddress.LOOPBACK_IP_V4, port).then((connection) {
56 connection.listen((_) { }, onDone: () => print('SUCCESS'));
57 connection.close();
58 });
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698