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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/web_socket_ping_test.dart
diff --git a/tests/standalone/io/web_socket_ping_test.dart b/tests/standalone/io/web_socket_ping_test.dart
index 29fec923d550e218b1352ca17c626536d6d060d8..a416a48fdfc75e463b1fd6876096304633f373bb 100644
--- a/tests/standalone/io/web_socket_ping_test.dart
+++ b/tests/standalone/io/web_socket_ping_test.dart
@@ -10,30 +10,44 @@
import "package:expect/expect.dart";
import "dart:async";
import "dart:io";
+import "dart:math";
+part "../../../sdk/lib/io/crypto.dart";
+
+
+const String webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
void testPing(int totalConnections) {
HttpServer.bind('localhost', 0).then((server) {
- server.transform(new WebSocketTransformer()).listen((webSocket) {
- webSocket.pingInterval = const Duration(milliseconds: 500);
- webSocket.drain();
+ int closed = 0;
+ server.listen((request) {
+ var response = request.response;
+ response.statusCode = HttpStatus.SWITCHING_PROTOCOLS;
+ response.headers.set(HttpHeaders.CONNECTION, "upgrade");
+ response.headers.set(HttpHeaders.UPGRADE, "websocket");
+ String key = request.headers.value("Sec-WebSocket-Key");
+ _SHA1 sha1 = new _SHA1();
+ sha1.add("$key$webSocketGUID".codeUnits);
+ String accept = _CryptoUtils.bytesToBase64(sha1.close());
+ response.headers.add("Sec-WebSocket-Accept", accept);
+ response.headers.contentLength = 0;
+ response.detachSocket().then((socket) {
+ socket.drain().then((_) {
+ socket.close();
+ closed++;
+ if (closed == totalConnections) {
+ server.close();
+ }
+ });
+ });
});
- var futures = [];
for (int i = 0; i < totalConnections; i++) {
- futures.add(
- WebSocket.connect('ws://localhost:${server.port}').then((webSocket) {
- webSocket.pingInterval = const Duration(milliseconds: 500);
+ WebSocket.connect('ws://localhost:${server.port}').then((webSocket) {
+ webSocket.pingInterval = const Duration(milliseconds: 100);
webSocket.drain();
- new Timer(const Duration(seconds: 2), () {
- // Should not be closed yet.
- Expect.equals(null, webSocket.closeCode);
- webSocket.close();
- });
- return webSocket.done;
- }));
+ });
}
- Future.wait(futures).then((_) => server.close());
});
}
« 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