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

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

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 1 month 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
« no previous file with comments | « tests/standalone/io/http_read_test.dart ('k') | tests/standalone/io/platform_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 library ServerTest; 10 library ServerTest;
11 11
12 import "package:expect/expect.dart"; 12 import "package:expect/expect.dart";
13 import "package:async_helper/async_helper.dart";
13 import "dart:async"; 14 import "dart:async";
14 import "dart:io"; 15 import "dart:io";
15 import "dart:isolate"; 16 import "dart:isolate";
16 part "testing_server.dart"; 17 part "testing_server.dart";
17 18
18 19
19 String getDataFilename(String path) => 20 String getDataFilename(String path) =>
20 new File(path).existsSync() ? path : '../$path'; 21 new File(path).existsSync() ? path : '../$path';
21 22
22 23
23 bool compareFileContent(String fileName1, String fileName2) { 24 bool compareFileContent(String fileName1, String fileName2) {
24 var contents1 = new File(fileName1).readAsStringSync(); 25 var contents1 = new File(fileName1).readAsStringSync();
25 var contents2 = new File(fileName2).readAsStringSync(); 26 var contents2 = new File(fileName2).readAsStringSync();
26 return contents1 == contents2; 27 return contents1 == contents2;
27 } 28 }
28 29
29 30
30 // This test does: 31 // This test does:
31 // 1. Opens a socket to the testing server. 32 // 1. Opens a socket to the testing server.
32 // 2. Pipes the content of a file to that sockets input stream. 33 // 2. Pipes the content of a file to that sockets input stream.
33 // 3. Creates a temp file. 34 // 3. Creates a temp file.
34 // 4. Pipes the socket output stream to the temp file. 35 // 4. Pipes the socket output stream to the temp file.
35 // 5. Expects the original file and the temp file to be equal. 36 // 5. Expects the original file and the temp file to be equal.
36 class PipeServerGame { 37 class PipeServerGame {
37 38
38 int count = 0; 39 int count = 0;
39 40
40 PipeServerGame.start() 41 PipeServerGame.start()
41 : _receivePort = new ReceivePort(), 42 : _messages = 0 {
42 _sendPort = null,
43 _messages = 0 {
44 _sendPort = spawnFunction(startPipeServer);
45 initialize(); 43 initialize();
46 } 44 }
47 45
48 void runTest() { 46 void runTest() {
49 47
50 void connectHandler() { 48 void connectHandler() {
51 String srcFileName = 49 String srcFileName =
52 getDataFilename("tests/standalone/io/readline_test1.dat"); 50 getDataFilename("tests/standalone/io/readline_test1.dat");
53 Stream fileInput = new File(srcFileName).openRead(); 51 Stream fileInput = new File(srcFileName).openRead();
54 fileInput.pipe(_socket).then((_) { 52 fileInput.pipe(_socket).then((_) {
(...skipping 21 matching lines...) Expand all
76 } 74 }
77 75
78 // Connect to the server. 76 // Connect to the server.
79 Socket.connect(TestingServer.HOST, _port).then((s) { 77 Socket.connect(TestingServer.HOST, _port).then((s) {
80 _socket = s; 78 _socket = s;
81 connectHandler(); 79 connectHandler();
82 }); 80 });
83 } 81 }
84 82
85 void initialize() { 83 void initialize() {
86 _receivePort.receive((var message, SendPort replyTo) { 84 var receivePort = new ReceivePort();
87 _port = message; 85 var remote = Isolate.spawn(startPipeServer, receivePort.sendPort);
86 receivePort.first.then((msg) {
87 this._port = msg[0];
88 this._closeSendPort = msg[1];
88 runTest(); 89 runTest();
89 }); 90 });
90 _sendPort.send(TestingServer.INIT, _receivePort.toSendPort());
91 } 91 }
92 92
93 void shutdown() { 93 void shutdown() {
94 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); 94 _closeSendPort.send(null);
95 _receivePort.close(); 95 asyncEnd();
96 } 96 }
97 97
98 int _port; 98 int _port;
99 ReceivePort _receivePort; 99 SendPort _closeSendPort;
100 SendPort _sendPort;
101 Socket _socket; 100 Socket _socket;
102 int _messages; 101 int _messages;
103 } 102 }
104 103
105 104
106 void startPipeServer() { 105 void startPipeServer(SendPort replyPort) {
107 var server = new PipeServer(); 106 var server = new PipeServer();
108 port.receive(server.dispatch); 107 server.init().then((port) {
108 replyPort.send([port, server.closeSendPort]);
109 });
109 } 110 }
110 111
111 112
112 // The testing server will simply pipe each connecting sockets input 113 // The testing server will simply pipe each connecting sockets input
113 // stream to its output stream. 114 // stream to its output stream.
114 class PipeServer extends TestingServer { 115 class PipeServer extends TestingServer {
115 void onConnection(Socket connection) { 116 void onConnection(Socket connection) {
116 connection.pipe(connection); 117 connection.pipe(connection);
117 } 118 }
118 } 119 }
119 120
120 121
121 main() { 122 main() {
123 asyncStart();
122 PipeServerGame echoServerGame = new PipeServerGame.start(); 124 PipeServerGame echoServerGame = new PipeServerGame.start();
123 } 125 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_read_test.dart ('k') | tests/standalone/io/platform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698