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

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

Issue 14864009: Keep track of when a socket has been destroyed (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove delete_handle marker. 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/socket.dart ('k') | tests/standalone/io/raw_socket_typed_data_test.dart » ('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";
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 List<int> expected = createTestData(); 143 List<int> expected = createTestData();
144 for (int i = 0; i < messageSize; i++) { 144 for (int i = 0; i < messageSize; i++) {
145 Expect.equals(expected[i], data[i]); 145 Expect.equals(expected[i], data[i]);
146 } 146 }
147 } 147 }
148 148
149 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { 149 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) {
150 server.listen((client) { 150 server.listen((client) {
151 int bytesRead = 0; 151 int bytesRead = 0;
152 int bytesWritten = 0; 152 int bytesWritten = 0;
153 bool closedEventReceived = false;
153 List<int> data = new List<int>(messageSize); 154 List<int> data = new List<int>(messageSize);
154 155
155 client.writeEventsEnabled = false; 156 client.writeEventsEnabled = false;
156 client.listen((event) { 157 client.listen((event) {
157 switch (event) { 158 switch (event) {
158 case RawSocketEvent.READ: 159 case RawSocketEvent.READ:
159 if (dropReads) { 160 if (dropReads) {
160 if (serverReadCount != 10) { 161 if (serverReadCount != 10) {
161 serverReadCount++; 162 serverReadCount++;
162 break; 163 break;
(...skipping 18 matching lines...) Expand all
181 if (bytesWritten < data.length) { 182 if (bytesWritten < data.length) {
182 client.writeEventsEnabled = true; 183 client.writeEventsEnabled = true;
183 } 184 }
184 if (bytesWritten == data.length) { 185 if (bytesWritten == data.length) {
185 client.shutdown(SocketDirection.SEND); 186 client.shutdown(SocketDirection.SEND);
186 } 187 }
187 break; 188 break;
188 case RawSocketEvent.READ_CLOSED: 189 case RawSocketEvent.READ_CLOSED:
189 server.close(); 190 server.close();
190 break; 191 break;
192 case RawSocketEvent.CLOSED:
193 Expect.isFalse(closedEventReceived);
194 closedEventReceived = true;
195 break;
191 default: throw "Unexpected event $event"; 196 default: throw "Unexpected event $event";
192 } 197 }
193 }); 198 },
199 onDone: () => Expect.isTrue(closedEventReceived));
194 }); 200 });
195 201
196 RawSocket.connect("127.0.0.1", server.port).then((socket) { 202 RawSocket.connect("127.0.0.1", server.port).then((socket) {
197 int bytesRead = 0; 203 int bytesRead = 0;
198 int bytesWritten = 0; 204 int bytesWritten = 0;
205 bool closedEventReceived = false;
199 List<int> data = createTestData(); 206 List<int> data = createTestData();
200 207
201 socket.listen((event) { 208 socket.listen((event) {
202 switch (event) { 209 switch (event) {
203 case RawSocketEvent.READ: 210 case RawSocketEvent.READ:
204 Expect.isTrue(socket.available() > 0); 211 Expect.isTrue(socket.available() > 0);
205 if (dropReads) { 212 if (dropReads) {
206 if (clientReadCount != 10) { 213 if (clientReadCount != 10) {
207 clientReadCount++; 214 clientReadCount++;
208 break; 215 break;
(...skipping 13 matching lines...) Expand all
222 if (bytesWritten < data.length) { 229 if (bytesWritten < data.length) {
223 socket.writeEventsEnabled = true; 230 socket.writeEventsEnabled = true;
224 } else { 231 } else {
225 data = new List<int>(messageSize); 232 data = new List<int>(messageSize);
226 } 233 }
227 break; 234 break;
228 case RawSocketEvent.READ_CLOSED: 235 case RawSocketEvent.READ_CLOSED:
229 verifyTestData(data); 236 verifyTestData(data);
230 socket.close(); 237 socket.close();
231 break; 238 break;
239 case RawSocketEvent.CLOSED:
240 Expect.isFalse(closedEventReceived);
241 closedEventReceived = true;
242 break;
232 default: throw "Unexpected event $event"; 243 default: throw "Unexpected event $event";
233 } 244 }
234 }, 245 },
235 onDone: () => port.close()); 246 onDone: () {
247 Expect.isTrue(closedEventReceived);
248 port.close();
249 });
236 }); 250 });
237 }); 251 });
238 } 252 }
239 253
240 testPauseServerSocket() { 254 testPauseServerSocket() {
241 const int socketCount = 10; 255 const int socketCount = 10;
242 var acceptCount = 0; 256 var acceptCount = 0;
243 var resumed = false; 257 var resumed = false;
244 258
245 ReceivePort port = new ReceivePort(); 259 ReceivePort port = new ReceivePort();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 int bytesWritten = 0; 295 int bytesWritten = 0;
282 int bytesRead = 0; 296 int bytesRead = 0;
283 var writeSubscription; 297 var writeSubscription;
284 var readSubscription; 298 var readSubscription;
285 299
286 ReceivePort port = new ReceivePort(); 300 ReceivePort port = new ReceivePort();
287 301
288 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { 302 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) {
289 Expect.isTrue(server.port > 0); 303 Expect.isTrue(server.port > 0);
290 server.listen((client) { 304 server.listen((client) {
305 bool closedEventReceived = false;
291 List<int> data = new List<int>.filled(messageSize, 0); 306 List<int> data = new List<int>.filled(messageSize, 0);
292 writeSubscription = client.listen((event) { 307 writeSubscription = client.listen((event) {
293 switch (event) { 308 switch (event) {
294 case RawSocketEvent.READ: 309 case RawSocketEvent.READ:
295 throw "Unexpected read event"; 310 throw "Unexpected read event";
296 case RawSocketEvent.WRITE: 311 case RawSocketEvent.WRITE:
297 if (pauseResumeCount == loopCount) return; 312 if (pauseResumeCount == loopCount) return;
298 Expect.isFalse(client.writeEventsEnabled); 313 Expect.isFalse(client.writeEventsEnabled);
299 Expect.equals(0, bytesRead); // Checks that reader is paused. 314 Expect.equals(0, bytesRead); // Checks that reader is paused.
300 bytesWritten += client.write( 315 bytesWritten += client.write(
301 data, bytesWritten, data.length - bytesWritten); 316 data, bytesWritten, data.length - bytesWritten);
302 // Ensure all data is written. When done disable the write 317 // Ensure all data is written. When done disable the write
303 // event and resume the receiver. 318 // event and resume the receiver.
304 if (bytesWritten == data.length) { 319 if (bytesWritten == data.length) {
305 writeSubscription.pause(); 320 writeSubscription.pause();
306 bytesWritten = 0; 321 bytesWritten = 0;
307 connected.future.then((_) { readSubscription.resume(); }); 322 connected.future.then((_) { readSubscription.resume(); });
308 } 323 }
309 client.writeEventsEnabled = true; 324 client.writeEventsEnabled = true;
310 break; 325 break;
311 case RawSocketEvent.READ_CLOSED: 326 case RawSocketEvent.READ_CLOSED:
312 client.close(); 327 client.close();
313 server.close(); 328 server.close();
314 break; 329 break;
330 case RawSocketEvent.CLOSED:
331 Expect.isFalse(closedEventReceived);
332 closedEventReceived = true;
333 break;
315 default: throw "Unexpected event $event"; 334 default: throw "Unexpected event $event";
316 } 335 }
317 }); 336 },
337 onDone: () => Expect.isTrue(closedEventReceived));
318 }); 338 });
319 339
320 RawSocket.connect("127.0.0.1", server.port).then((socket) { 340 RawSocket.connect("127.0.0.1", server.port).then((socket) {
341 bool closedEventReceived = false;
321 socket.writeEventsEnabled = false; 342 socket.writeEventsEnabled = false;
322 readSubscription = socket.listen((event) { 343 readSubscription = socket.listen((event) {
323 switch (event) { 344 switch (event) {
324 case RawSocketEvent.READ: 345 case RawSocketEvent.READ:
325 Expect.equals(0, bytesWritten); // Checks that writer is paused. 346 Expect.equals(0, bytesWritten); // Checks that writer is paused.
326 Expect.isTrue(socket.available() > 0); 347 Expect.isTrue(socket.available() > 0);
327 var buffer = socket.read(); 348 var buffer = socket.read();
328 bytesRead += buffer.length; 349 bytesRead += buffer.length;
329 // Ensure all data is read. When done pause and resume the sender 350 // Ensure all data is read. When done pause and resume the sender
330 if (bytesRead == messageSize) { 351 if (bytesRead == messageSize) {
331 if (++pauseResumeCount == loopCount) { 352 if (++pauseResumeCount == loopCount) {
332 socket.close(); 353 socket.close();
333 port.close(); 354 port.close();
334 } else { 355 } else {
335 readSubscription.pause(); 356 readSubscription.pause();
336 } 357 }
337 // Always resume writer as it needs the read closed 358 // Always resume writer as it needs the read closed
338 // event when done. 359 // event when done.
339 bytesRead = 0; 360 bytesRead = 0;
340 writeSubscription.resume(); 361 writeSubscription.resume();
341 } 362 }
342 break; 363 break;
343 case RawSocketEvent.WRITE: 364 case RawSocketEvent.WRITE:
344 throw "Unexpected write event"; 365 throw "Unexpected write event";
345 case RawSocketEvent.READ_CLOSED: 366 case RawSocketEvent.READ_CLOSED:
346 throw "Unexpected close event"; 367 throw "Unexpected read closed event";
368 case RawSocketEvent.CLOSED:
369 Expect.isFalse(closedEventReceived);
370 closedEventReceived = true;
371 break;
347 default: throw "Unexpected event $event"; 372 default: throw "Unexpected event $event";
348 } 373 }
349 }); 374 },
375 onDone: () => Expect.isTrue(closedEventReceived));
350 readSubscription.pause(); 376 readSubscription.pause();
351 connected.complete(true); 377 connected.complete(true);
352 }); 378 });
353 }); 379 });
354 } 380 }
355 381
356 main() { 382 main() {
357 testArguments(); 383 testArguments();
358 testSimpleBind(); 384 testSimpleBind();
359 testCloseOneEnd("client"); 385 testCloseOneEnd("client");
360 testCloseOneEnd("server"); 386 testCloseOneEnd("server");
361 testInvalidBind(); 387 testInvalidBind();
362 testSimpleConnect(); 388 testSimpleConnect();
363 testServerListenAfterConnect(); 389 testServerListenAfterConnect();
364 testSimpleReadWrite(dropReads: false); 390 testSimpleReadWrite(dropReads: false);
365 testSimpleReadWrite(dropReads: true); 391 testSimpleReadWrite(dropReads: true);
366 testPauseServerSocket(); 392 testPauseServerSocket();
367 testPauseSocket(); 393 testPauseSocket();
368 } 394 }
OLDNEW
« no previous file with comments | « sdk/lib/io/socket.dart ('k') | tests/standalone/io/raw_socket_typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698