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

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

Issue 23627003: Fix web_socket_ping_test to not use any timeouts longer than 100 ms. (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
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('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 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import "dart:async"; 11 import "dart:async";
12 import "dart:io"; 12 import "dart:io";
13 import "dart:math";
13 14
15 part "../../../sdk/lib/io/crypto.dart";
16
17
18 const String webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
14 19
15 void testPing(int totalConnections) { 20 void testPing(int totalConnections) {
16 HttpServer.bind('localhost', 0).then((server) { 21 HttpServer.bind('localhost', 0).then((server) {
17 server.transform(new WebSocketTransformer()).listen((webSocket) { 22 int closed = 0;
18 webSocket.pingInterval = const Duration(milliseconds: 500); 23 server.listen((request) {
19 webSocket.drain(); 24 var response = request.response;
25 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS;
26 response.headers.set(HttpHeaders.CONNECTION, "upgrade");
27 response.headers.set(HttpHeaders.UPGRADE, "websocket");
28 String key = request.headers.value("Sec-WebSocket-Key");
29 _SHA1 sha1 = new _SHA1();
30 sha1.add("$key$webSocketGUID".codeUnits);
31 String accept = _CryptoUtils.bytesToBase64(sha1.close());
32 response.headers.add("Sec-WebSocket-Accept", accept);
33 response.headers.contentLength = 0;
34 response.detachSocket().then((socket) {
35 socket.drain().then((_) {
36 socket.close();
37 closed++;
38 if (closed == totalConnections) {
39 server.close();
40 }
41 });
42 });
20 }); 43 });
21 44
22 var futures = [];
23 for (int i = 0; i < totalConnections; i++) { 45 for (int i = 0; i < totalConnections; i++) {
24 futures.add( 46 WebSocket.connect('ws://localhost:${server.port}').then((webSocket) {
25 WebSocket.connect('ws://localhost:${server.port}').then((webSocket) { 47 webSocket.pingInterval = const Duration(milliseconds: 100);
26 webSocket.pingInterval = const Duration(milliseconds: 500);
27 webSocket.drain(); 48 webSocket.drain();
28 new Timer(const Duration(seconds: 2), () { 49 });
29 // Should not be closed yet.
30 Expect.equals(null, webSocket.closeCode);
31 webSocket.close();
32 });
33 return webSocket.done;
34 }));
35 } 50 }
36 Future.wait(futures).then((_) => server.close());
37 }); 51 });
38 } 52 }
39 53
40 54
41 void main() { 55 void main() {
42 testPing(10); 56 testPing(10);
43 } 57 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698