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

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

Issue 19596008: Implement correct back-throttleing for web-sockets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix comment Created 7 years, 5 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 | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | 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 13
14 14
15 void testPing(int totalConnections) { 15 void testPing(int totalConnections) {
16 HttpServer.bind('localhost', 0).then((server) { 16 HttpServer.bind('localhost', 0).then((server) {
17 // The completers will be completed when the pingInterval have terminated
18 // the webSockets.
19 var completers = new List.generate(
20 totalConnections, (_) => new Completer());
21
22 int conns = 0;
17 server.transform(new WebSocketTransformer()).listen((webSocket) { 23 server.transform(new WebSocketTransformer()).listen((webSocket) {
18 webSocket.pingInterval = const Duration(milliseconds: 500); 24 int i = conns++;
25 webSocket.pingInterval = const Duration(milliseconds: 100);
19 webSocket.drain(); 26 webSocket.drain();
27 var timer = new Timer.periodic(const Duration(milliseconds: 10), (_) {
28 webSocket.add(new List.filled(10 * 1024, 0));
29 });
30 webSocket.done.then((_) {
31 completers[i].complete();
32 timer.cancel();
33 Expect.equals(WebSocketStatus.GOING_AWAY, webSocket.closeCode);
34 webSocket.close();
35 });
20 }); 36 });
21 37
22 var futures = []; 38 var futures = [];
23 for (int i = 0; i < totalConnections; i++) { 39 for (int i = 0; i < totalConnections; i++) {
24 futures.add( 40 futures.add(
25 WebSocket.connect('ws://localhost:${server.port}').then((webSocket) { 41 WebSocket.connect('ws://localhost:${server.port}')
26 webSocket.pingInterval = const Duration(milliseconds: 500); 42 .then((webSocket) {
27 webSocket.drain(); 43 // Don't drain yet, to block data.
28 new Timer(const Duration(seconds: 2), () { 44 // Once the server is done, drain the peers.
29 // Should not be closed yet. 45 return Future.wait(completers.map((c) => c.future))
30 Expect.equals(null, webSocket.closeCode); 46 .then((_) => webSocket.drain());
31 webSocket.close(); 47 }));
32 });
33 return webSocket.done;
34 }));
35 } 48 }
36 Future.wait(futures).then((_) => server.close()); 49 Future.wait(futures).then((_) => server.close());
37 }); 50 });
38 } 51 }
39 52
40 53
41 void main() { 54 void main() {
42 testPing(10); 55 testPing(10);
43 } 56 }
OLDNEW
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698