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

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

Issue 11946042: Speed up web_socket_test by running subtests in parallel. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove pipelining and Futures. Created 7 years, 11 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 5
6 // TODO(7157): Remove this test once the bug is fixed. 6 // TODO(7157): Remove this test once the bug is fixed.
7 // This is a copy of web_socket_test.dart with the secure connection 7 // This is a copy of web_socket_test.dart with the secure connection
8 // tests disabled, so it does not crash on Windows. 8 // tests disabled, so it does not crash on Windows.
9 import "dart:async"; 9 import "dart:async";
10 import "dart:io"; 10 import "dart:io";
11 import "dart:isolate"; 11 import "dart:isolate";
12 import "dart:scalarlist"; 12 import "dart:scalarlist";
13 import "dart:uri"; 13 import "dart:uri";
14 14
15 const SERVER_ADDRESS = "127.0.0.1"; 15 const SERVER_ADDRESS = "127.0.0.1";
16 const HOST_NAME = "localhost"; 16 const HOST_NAME = "localhost";
17 17
18 // We will run the tests once over HTTP and once over HTTPS. 18 // We will run the tests once over HTTP and once over HTTPS.
19 bool secure = false; 19 bool secure = false;
20 20
21 Future testRequestResponseClientCloses( 21 void testRequestResponseClientCloses(
22 int totalConnections, int closeStatus, String closeReason) { 22 int totalConnections, int closeStatus, String closeReason) {
23 Completer done = new Completer(); 23 ReceivePort keepAlive = new ReceivePort();
24 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 24 HttpServer server = secure ? new HttpsServer() : new HttpServer();
25 HttpClient client = new HttpClient(); 25 HttpClient client = new HttpClient();
26 26
27 server.listen(SERVER_ADDRESS, 27 server.listen(SERVER_ADDRESS,
28 0, 28 0,
29 backlog: totalConnections, 29 backlog: totalConnections,
30 certificate_name: "CN=$HOST_NAME"); 30 certificate_name: "CN=$HOST_NAME");
31 31
32 // Create a web socket handler and set it as the HTTP server default handler. 32 // Create a web socket handler and set it as the HTTP server default handler.
33 WebSocketHandler wsHandler = new WebSocketHandler(); 33 WebSocketHandler wsHandler = new WebSocketHandler();
(...skipping 28 matching lines...) Expand all
62 }; 62 };
63 wsconn.onClosed = (status, reason) { 63 wsconn.onClosed = (status, reason) {
64 Expect.equals(closeStatus == null 64 Expect.equals(closeStatus == null
65 ? WebSocketStatus.NO_STATUS_RECEIVED 65 ? WebSocketStatus.NO_STATUS_RECEIVED
66 : closeStatus, status); 66 : closeStatus, status);
67 Expect.equals("", reason); 67 Expect.equals("", reason);
68 closeCount++; 68 closeCount++;
69 if (closeCount == totalConnections) { 69 if (closeCount == totalConnections) {
70 client.shutdown(); 70 client.shutdown();
71 server.close(); 71 server.close();
72 done.complete(null); 72 keepAlive.close();
73 } 73 }
74 }; 74 };
75 } 75 }
76 return done.future;
77 } 76 }
78 77
79 78
80 Future testRequestResponseServerCloses( 79 void testRequestResponseServerCloses(
81 int totalConnections, int closeStatus, String closeReason) { 80 int totalConnections, int closeStatus, String closeReason) {
82 Completer done = new Completer(); 81 ReceivePort keepAlive = new ReceivePort();
83 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 82 HttpServer server = secure ? new HttpsServer() : new HttpServer();
84 HttpClient client = new HttpClient(); 83 HttpClient client = new HttpClient();
85 84
86 server.listen(SERVER_ADDRESS, 85 server.listen(SERVER_ADDRESS,
87 0, 86 0,
88 backlog: totalConnections, 87 backlog: totalConnections,
89 certificate_name: "CN=$HOST_NAME"); 88 certificate_name: "CN=$HOST_NAME");
90 89
91 // Create a web socket handler and set is as the HTTP server default 90 // Create a web socket handler and set is as the HTTP server default
92 // handler. 91 // handler.
(...skipping 13 matching lines...) Expand all
106 }; 105 };
107 conn.onClosed = (status, reason) { 106 conn.onClosed = (status, reason) {
108 Expect.equals(closeStatus == null 107 Expect.equals(closeStatus == null
109 ? WebSocketStatus.NO_STATUS_RECEIVED 108 ? WebSocketStatus.NO_STATUS_RECEIVED
110 : closeStatus, status); 109 : closeStatus, status);
111 Expect.equals("", reason); 110 Expect.equals("", reason);
112 closeCount++; 111 closeCount++;
113 if (closeCount == totalConnections) { 112 if (closeCount == totalConnections) {
114 client.shutdown(); 113 client.shutdown();
115 server.close(); 114 server.close();
116 done.complete(null); 115 keepAlive.close();
117 } 116 }
118 }; 117 };
119 conn.send(messageText); 118 conn.send(messageText);
120 }; 119 };
121 server.defaultRequestHandler = wsHandler.onRequest; 120 server.defaultRequestHandler = wsHandler.onRequest;
122 121
123 for (int i = 0; i < totalConnections; i++) { 122 for (int i = 0; i < totalConnections; i++) {
124 HttpClientConnection conn = client.getUrl(new Uri.fromString( 123 HttpClientConnection conn = client.getUrl(new Uri.fromString(
125 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/')); 124 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/'));
126 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 125 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
127 wsconn.onMessage = (message) => wsconn.send(message); 126 wsconn.onMessage = (message) => wsconn.send(message);
128 wsconn.onClosed = (status, reason) { 127 wsconn.onClosed = (status, reason) {
129 Expect.equals(closeStatus == null 128 Expect.equals(closeStatus == null
130 ? WebSocketStatus.NO_STATUS_RECEIVED 129 ? WebSocketStatus.NO_STATUS_RECEIVED
131 : closeStatus, status); 130 : closeStatus, status);
132 Expect.equals(closeReason == null ? "" : closeReason, reason); 131 Expect.equals(closeReason == null ? "" : closeReason, reason);
133 }; 132 };
134 } 133 }
135 return done.future;
136 } 134 }
137 135
138 136
139 Future testMessageLength(int messageLength) { 137 void testMessageLength(int messageLength) {
140 Completer done = new Completer(); 138 ReceivePort keepAlive = new ReceivePort();
141 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 139 HttpServer server = secure ? new HttpsServer() : new HttpServer();
142 HttpClient client = new HttpClient(); 140 HttpClient client = new HttpClient();
143 bool serverReceivedMessage = false; 141 bool serverReceivedMessage = false;
144 bool clientReceivedMessage = false; 142 bool clientReceivedMessage = false;
145 143
146 server.listen(SERVER_ADDRESS, 144 server.listen(SERVER_ADDRESS,
147 0, 145 0,
148 backlog: 1, 146 backlog: 1,
149 certificate_name: "CN=$HOST_NAME"); 147 certificate_name: "CN=$HOST_NAME");
150 148
(...skipping 18 matching lines...) Expand all
169 wsconn.onMessage = (message) { 167 wsconn.onMessage = (message) {
170 clientReceivedMessage = true; 168 clientReceivedMessage = true;
171 Expect.listEquals(originalMessage, message); 169 Expect.listEquals(originalMessage, message);
172 wsconn.close(); 170 wsconn.close();
173 }; 171 };
174 wsconn.onClosed = (status, reason) { 172 wsconn.onClosed = (status, reason) {
175 Expect.isTrue(serverReceivedMessage); 173 Expect.isTrue(serverReceivedMessage);
176 Expect.isTrue(clientReceivedMessage); 174 Expect.isTrue(clientReceivedMessage);
177 client.shutdown(); 175 client.shutdown();
178 server.close(); 176 server.close();
179 done.complete(null); 177 keepAlive.close();
180 }; 178 };
181 wsconn.onOpen = () { 179 wsconn.onOpen = () {
182 wsconn.send(originalMessage); 180 wsconn.send(originalMessage);
183 }; 181 };
184 return done.future;
185 } 182 }
186 183
187 184
188 Future testNoUpgrade() { 185 void testNoUpgrade() {
189 Completer done = new Completer(); 186 ReceivePort keepAlive = new ReceivePort();
190 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 187 HttpServer server = secure ? new HttpsServer() : new HttpServer();
191 HttpClient client = new HttpClient(); 188 HttpClient client = new HttpClient();
192 189
193 server.listen(SERVER_ADDRESS, 190 server.listen(SERVER_ADDRESS,
194 0, 191 0,
195 backlog: 5, 192 backlog: 5,
196 certificate_name: "CN=$HOST_NAME"); 193 certificate_name: "CN=$HOST_NAME");
197 194
198 // Create a server which always responds with a redirect. 195 // Create a server which always responds with a redirect.
199 server.defaultRequestHandler = (request, response) { 196 server.defaultRequestHandler = (request, response) {
200 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 197 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
201 response.outputStream.close(); 198 response.outputStream.close();
202 }; 199 };
203 200
204 HttpClientConnection conn = client.getUrl(new Uri.fromString( 201 HttpClientConnection conn = client.getUrl(new Uri.fromString(
205 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/')); 202 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/'));
206 conn.followRedirects = false; 203 conn.followRedirects = false;
207 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 204 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
208 wsconn.onNoUpgrade = (response) { 205 wsconn.onNoUpgrade = (response) {
209 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode); 206 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
210 client.shutdown(); 207 client.shutdown();
211 server.close(); 208 server.close();
212 done.complete(null); 209 keepAlive.close();
213 }; 210 };
214 return done.future;
215 } 211 }
216 212
217 213
218 Future testUsePOST() { 214 void testUsePOST() {
219 Completer done = new Completer(); 215 ReceivePort keepAlive = new ReceivePort();
220 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 216 HttpServer server = secure ? new HttpsServer() : new HttpServer();
221 HttpClient client = new HttpClient(); 217 HttpClient client = new HttpClient();
222 218
223 server.listen(SERVER_ADDRESS, 219 server.listen(SERVER_ADDRESS,
224 0, 220 0,
225 backlog: 5, 221 backlog: 5,
226 certificate_name: "CN=$HOST_NAME"); 222 certificate_name: "CN=$HOST_NAME");
227 223
228 // Create a web socket handler and set is as the HTTP server default 224 // Create a web socket handler and set is as the HTTP server default
229 // handler. 225 // handler.
230 int closeCount = 0; 226 int closeCount = 0;
231 WebSocketHandler wsHandler = new WebSocketHandler(); 227 WebSocketHandler wsHandler = new WebSocketHandler();
232 wsHandler.onOpen = (WebSocketConnection conn) { 228 wsHandler.onOpen = (WebSocketConnection conn) {
233 Expect.fail("No connection expected"); 229 Expect.fail("No connection expected");
234 }; 230 };
235 server.defaultRequestHandler = wsHandler.onRequest; 231 server.defaultRequestHandler = wsHandler.onRequest;
236 232
237 HttpClientConnection conn = client.postUrl(new Uri.fromString( 233 HttpClientConnection conn = client.postUrl(new Uri.fromString(
238 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/')); 234 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/'));
239 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 235 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
240 wsconn.onNoUpgrade = (response) { 236 wsconn.onNoUpgrade = (response) {
241 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode); 237 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode);
242 client.shutdown(); 238 client.shutdown();
243 server.close(); 239 server.close();
244 done.complete(null); 240 keepAlive.close();
245 }; 241 };
246 return done.future;
247 } 242 }
248 243
249 244
250 class WebSocketInfo { 245 class WebSocketInfo {
251 int messageCount = 0; 246 int messageCount = 0;
252 } 247 }
253 248
254 249
255 Future testHashCode(int totalConnections) { 250 void testHashCode(int totalConnections) {
256 Completer done = new Completer(); 251 ReceivePort keepAlive = new ReceivePort();
257 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 252 HttpServer server = secure ? new HttpsServer() : new HttpServer();
258 HttpClient client = new HttpClient(); 253 HttpClient client = new HttpClient();
259 Map connections = new Map(); 254 Map connections = new Map();
260 255
261 server.listen(SERVER_ADDRESS, 256 server.listen(SERVER_ADDRESS,
262 0, 257 0,
263 backlog: totalConnections, 258 backlog: totalConnections,
264 certificate_name: "CN=$HOST_NAME"); 259 certificate_name: "CN=$HOST_NAME");
265 260
266 void handleMessage(conn, message) { 261 void handleMessage(conn, message) {
(...skipping 17 matching lines...) Expand all
284 conn.onMessage = (Object message) { 279 conn.onMessage = (Object message) {
285 handleMessage(conn, message); 280 handleMessage(conn, message);
286 }; 281 };
287 conn.onClosed = (status, reason) { 282 conn.onClosed = (status, reason) {
288 closeCount++; 283 closeCount++;
289 var info = connections[conn]; 284 var info = connections[conn];
290 Expect.equals(10, info.messageCount); 285 Expect.equals(10, info.messageCount);
291 if (closeCount == totalConnections) { 286 if (closeCount == totalConnections) {
292 client.shutdown(); 287 client.shutdown();
293 server.close(); 288 server.close();
294 done.complete(); 289 keepAlive.close();
295 } 290 }
296 }; 291 };
297 conn.send(messageText); 292 conn.send(messageText);
298 }; 293 };
299 server.defaultRequestHandler = wsHandler.onRequest; 294 server.defaultRequestHandler = wsHandler.onRequest;
300 295
301 for (int i = 0; i < totalConnections; i++) { 296 for (int i = 0; i < totalConnections; i++) {
302 HttpClientConnection conn = client.getUrl(new Uri.fromString( 297 HttpClientConnection conn = client.getUrl(new Uri.fromString(
303 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/')); 298 '${secure ? "https" : "http"}://$HOST_NAME:${server.port}/'));
304 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 299 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
305 wsconn.onMessage = (message) => wsconn.send(message); 300 wsconn.onMessage = (message) => wsconn.send(message);
306 } 301 }
307 return done.future;
308 } 302 }
309 303
310 304
311 Future testW3CInterface( 305 void testW3CInterface(
312 int totalConnections, int closeStatus, String closeReason) { 306 int totalConnections, int closeStatus, String closeReason) {
307 ReceivePort keepAlive = new ReceivePort();
313 List<Future> tasks = []; 308 List<Future> tasks = [];
314 HttpServer server = secure ? new HttpsServer() : new HttpServer(); 309 HttpServer server = secure ? new HttpsServer() : new HttpServer();
315 310
316 server.listen(SERVER_ADDRESS, 311 server.listen(SERVER_ADDRESS,
317 0, 312 0,
318 backlog: totalConnections, 313 backlog: totalConnections,
319 certificate_name: "CN=$HOST_NAME"); 314 certificate_name: "CN=$HOST_NAME");
320 315
321 // Create a web socket handler and set is as the HTTP server default 316 // Create a web socket handler and set is as the HTTP server default
322 // handler. 317 // handler.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 Expect.equals(3002, event.code); 377 Expect.equals(3002, event.code);
383 Expect.equals("Got tired", event.reason); 378 Expect.equals("Got tired", event.reason);
384 Expect.equals(WebSocket.CLOSED, websocket.readyState); 379 Expect.equals(WebSocket.CLOSED, websocket.readyState);
385 clientDone.complete(null); 380 clientDone.complete(null);
386 }; 381 };
387 } 382 }
388 383
389 for (int i = 0; i < totalConnections; i++) { 384 for (int i = 0; i < totalConnections; i++) {
390 webSocketConnection(); 385 webSocketConnection();
391 } 386 }
392 return Future.wait(tasks); 387 Future.wait(tasks).then((_) {
388 keepAlive.close();
389 });
393 } 390 }
394 391
395 392
396 void InitializeSSL() { 393 void InitializeSSL() {
397 var testPkcertDatabase = 394 var testPkcertDatabase =
398 new Path(new Options().script).directoryPath.append("pkcert/"); 395 new Path(new Options().script).directoryPath.append("pkcert/");
399 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), 396 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(),
400 password: "dartdart"); 397 password: "dartdart");
401 } 398 }
402 399
403 400
404 Future runTests() => 401 /**
405 testRequestResponseClientCloses(2, null, null).then((_) => 402 * Run all the tests in parallel, complete when the last one finishes.
406 testRequestResponseClientCloses(2, 3001, null)).then((_) => 403 */
407 testRequestResponseClientCloses(2, 3002, "Got tired")).then((_) => 404 runTests() {
408 testRequestResponseServerCloses(2, null, null)).then((_) => 405 testRequestResponseClientCloses(2, null, null);
409 testRequestResponseServerCloses(2, 3001, null)).then((_) => 406 testRequestResponseClientCloses(2, 3001, null);
410 testRequestResponseServerCloses(2, 3002, "Got tired")).then((_) => 407 testRequestResponseClientCloses(2, 3002, "Got tired");
411 testMessageLength(125)).then((_) => 408 testRequestResponseServerCloses(2, null, null);
412 testMessageLength(126)).then((_) => 409 testRequestResponseServerCloses(2, 3001, null);
413 testMessageLength(127)).then((_) => 410 testRequestResponseServerCloses(2, 3002, "Got tired");
414 testMessageLength(65535)).then((_) => 411 testMessageLength(125);
415 testMessageLength(65536)).then((_) => 412 testMessageLength(126);
416 testNoUpgrade()).then((_) => 413 testMessageLength(127);
417 testUsePOST()).then((_) => 414 testMessageLength(65535);
418 testHashCode(2)).then((_) => 415 testMessageLength(65536);
419 testW3CInterface(2, 3002, "Got tired")); 416 testNoUpgrade();
417 testUsePOST();
418 testHashCode(2);
419 testW3CInterface(2, 3002, "Got tired");
420 }
420 421
421 422
422 main() { 423 main() {
423 ReceivePort keepAlive = new ReceivePort(); 424 runTests();
424 runTests().then((_) {
425 keepAlive.close();
426 });
427 } 425 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/web_socket_test.dart » ('j') | tests/standalone/io/web_socket_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698