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

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

Issue 10377124: Add a hash code to client and server web socket connections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 7 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 | « runtime/bin/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) 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 #import("dart:io"); 6 #import("dart:io");
7 7
8 void testRequestResponseClientCloses( 8 void testRequestResponseClientCloses(
9 int totalConnections, int closeStatus, String closeReason) { 9 int totalConnections, int closeStatus, String closeReason) {
10 HttpServer server = new HttpServer(); 10 HttpServer server = new HttpServer();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 HttpClientConnection conn = client.post("127.0.0.1", server.port, "/"); 143 HttpClientConnection conn = client.post("127.0.0.1", server.port, "/");
144 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 144 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
145 wsconn.onNoUpgrade = (response) { 145 wsconn.onNoUpgrade = (response) {
146 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode); 146 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode);
147 client.shutdown(); 147 client.shutdown();
148 server.close(); 148 server.close();
149 }; 149 };
150 } 150 }
151 151
152 152
153 class WebSocketInfo {
154 int messageCount = 0;
155 }
156
157
158 void testHashCode(int totalConnections) {
159 HttpServer server = new HttpServer();
160 HttpClient client = new HttpClient();
161 Map connections = new Map();
162
163 server.listen("127.0.0.1", 0, totalConnections);
164
165 void handleMessage(conn, message) {
166 var info = connections[conn];
167 Expect.isNotNull(info);
168 info.messageCount++;
169 if (info.messageCount < 10) {
170 conn.send(message);
171 } else {
172 conn.close();
173 }
174 }
175
176 // Create a web socket handler and set is as the HTTP server default
177 // handler.
178 int closeCount = 0;
179 WebSocketHandler wsHandler = new WebSocketHandler();
180 wsHandler.onOpen = (WebSocketConnection conn) {
181 connections[conn] = new WebSocketInfo();
182 String messageText = "Hello, world!";
183 conn.onMessage = (Object message) {
184 handleMessage(conn, message);
185 };
186 conn.onClosed = (status, reason) {
187 closeCount++;
188 var info = connections[conn];
189 Expect.equals(10, info.messageCount);
190 if (closeCount == totalConnections) {
191 client.shutdown();
192 server.close();
193 }
194 };
195 conn.send(messageText);
196 };
197 server.defaultRequestHandler = wsHandler.onRequest;
198
199 for (int i = 0; i < totalConnections; i++) {
200 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
201 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
202 wsconn.onMessage = (message) => wsconn.send(message);
203 }
204 }
205
206
153 void testW3CInterface( 207 void testW3CInterface(
154 int totalConnections, int closeStatus, String closeReason) { 208 int totalConnections, int closeStatus, String closeReason) {
155 HttpServer server = new HttpServer(); 209 HttpServer server = new HttpServer();
156 210
157 server.listen("127.0.0.1", 0, totalConnections); 211 server.listen("127.0.0.1", 0, totalConnections);
158 212
159 // Create a web socket handler and set is as the HTTP server default 213 // Create a web socket handler and set is as the HTTP server default
160 // handler. 214 // handler.
161 int closeCount = 0; 215 int closeCount = 0;
162 WebSocketHandler wsHandler = new WebSocketHandler(); 216 WebSocketHandler wsHandler = new WebSocketHandler();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 279
226 main() { 280 main() {
227 testRequestResponseClientCloses(2, null, null); 281 testRequestResponseClientCloses(2, null, null);
228 testRequestResponseClientCloses(2, 3001, null); 282 testRequestResponseClientCloses(2, 3001, null);
229 testRequestResponseClientCloses(2, 3002, "Got tired"); 283 testRequestResponseClientCloses(2, 3002, "Got tired");
230 testRequestResponseServerCloses(2, null, null); 284 testRequestResponseServerCloses(2, null, null);
231 testRequestResponseServerCloses(2, 3001, null); 285 testRequestResponseServerCloses(2, 3001, null);
232 testRequestResponseServerCloses(2, 3002, "Got tired"); 286 testRequestResponseServerCloses(2, 3002, "Got tired");
233 testNoUpgrade(); 287 testNoUpgrade();
234 testUsePOST(); 288 testUsePOST();
289 testHashCode(2);
235 290
236 testW3CInterface(2, 3002, "Got tired"); 291 testW3CInterface(2, 3002, "Got tired");
237 } 292 }
OLDNEW
« no previous file with comments | « runtime/bin/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698