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

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

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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
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 // 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 // Test socket close events. 10 // Test socket close events.
(...skipping 15 matching lines...) Expand all
26 _dataEvents = 0, 26 _dataEvents = 0,
27 _closeEvents = 0, 27 _closeEvents = 0,
28 _errorEvents = 0, 28 _errorEvents = 0,
29 _iterations = 0 { 29 _iterations = 0 {
30 _sendPort = spawnFunction(startSocketCloseServer); 30 _sendPort = spawnFunction(startSocketCloseServer);
31 initialize(); 31 initialize();
32 } 32 }
33 33
34 void proceed() { 34 void proceed() {
35 if (_iterations < ITERATIONS) { 35 if (_iterations < ITERATIONS) {
36 new Timer(0, sendData); 36 Timer.run(sendData);
37 } else { 37 } else {
38 shutdown(); 38 shutdown();
39 } 39 }
40 } 40 }
41 41
42 void sendData(Timer timer) { 42 void sendData() {
43 43
44 void dataHandler() { 44 void dataHandler() {
45 switch (_mode) { 45 switch (_mode) {
46 case 0: 46 case 0:
47 case 1: 47 case 1:
48 case 2: 48 case 2:
49 Expect.fail("No data expected"); 49 Expect.fail("No data expected");
50 break; 50 break;
51 case 3: 51 case 3:
52 case 4: 52 case 4:
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 connection.inputStream.onData = dataHandler; 311 connection.inputStream.onData = dataHandler;
312 connection.inputStream.onClosed = closeHandler; 312 connection.inputStream.onClosed = closeHandler;
313 connection.onError = errorHandler; 313 connection.onError = errorHandler;
314 } 314 }
315 315
316 void errorHandlerServer(Exception e) { 316 void errorHandlerServer(Exception e) {
317 Expect.fail("Server socket error"); 317 Expect.fail("Server socket error");
318 } 318 }
319 319
320 waitForResult(Timer timer) { 320 waitForResult() {
321 // Make sure all iterations have been run. In multiple of these 321 // Make sure all iterations have been run. In multiple of these
322 // scenarios it is possible to get the SERVERSHUTDOWN message 322 // scenarios it is possible to get the SERVERSHUTDOWN message
323 // before we have received the last close event on the 323 // before we have received the last close event on the
324 // server. In these cases we wait for the correct number of 324 // server. In these cases we wait for the correct number of
325 // close events. 325 // close events.
326 if (_iterations == ITERATIONS && 326 if (_iterations == ITERATIONS &&
327 (_closeEvents == ITERATIONS || 327 (_closeEvents == ITERATIONS ||
328 (_mode == 2 || _mode == 3 || _mode == 4))) { 328 (_mode == 2 || _mode == 3 || _mode == 4))) {
329 switch (_mode) { 329 switch (_mode) {
330 case 0: 330 case 0:
(...skipping 18 matching lines...) Expand all
349 Expect.equals(ITERATIONS, _closeEvents); 349 Expect.equals(ITERATIONS, _closeEvents);
350 break; 350 break;
351 default: 351 default:
352 Expect.fail("Unknown test mode"); 352 Expect.fail("Unknown test mode");
353 } 353 }
354 Expect.equals(0, _errorEvents); 354 Expect.equals(0, _errorEvents);
355 _server.close(); 355 _server.close();
356 port.close(); 356 port.close();
357 _donePort.send(null); 357 _donePort.send(null);
358 } else { 358 } else {
359 new Timer(100, waitForResult); 359 new Timer(new Duration(milliseconds: 100), waitForResult);
360 } 360 }
361 } 361 }
362 362
363 void dispatch(message, replyTo) { 363 void dispatch(message, replyTo) {
364 _donePort = replyTo; 364 _donePort = replyTo;
365 if (message != SERVERSHUTDOWN) { 365 if (message != SERVERSHUTDOWN) {
366 _readBytes = 0; 366 _readBytes = 0;
367 _errorEvents = 0; 367 _errorEvents = 0;
368 _dataEvents = 0; 368 _dataEvents = 0;
369 _closeEvents = 0; 369 _closeEvents = 0;
370 _iterations = 0; 370 _iterations = 0;
371 _mode = message; 371 _mode = message;
372 _server = new ServerSocket(HOST, 0, 10); 372 _server = new ServerSocket(HOST, 0, 10);
373 Expect.equals(true, _server != null); 373 Expect.equals(true, _server != null);
374 _server.onConnection = (connection) { 374 _server.onConnection = (connection) {
375 var data = new ConnectionData(connection); 375 var data = new ConnectionData(connection);
376 connectionHandler(data); 376 connectionHandler(data);
377 }; 377 };
378 _server.onError = errorHandlerServer; 378 _server.onError = errorHandlerServer;
379 replyTo.send(_server.port, null); 379 replyTo.send(_server.port, null);
380 } else { 380 } else {
381 new Timer(0, waitForResult); 381 Timer.run(waitForResult);
382 } 382 }
383 } 383 }
384 384
385 ServerSocket _server; 385 ServerSocket _server;
386 SendPort _donePort; 386 SendPort _donePort;
387 int _readBytes; 387 int _readBytes;
388 int _errorEvents; 388 int _errorEvents;
389 int _dataEvents; 389 int _dataEvents;
390 int _closeEvents; 390 int _closeEvents;
391 int _iterations; 391 int _iterations;
(...skipping 17 matching lines...) Expand all
409 var tests = 9; 409 var tests = 9;
410 var port = new ReceivePort(); 410 var port = new ReceivePort();
411 var completed = 0; 411 var completed = 0;
412 port.receive((message, ignore) { 412 port.receive((message, ignore) {
413 if (++completed == tests) port.close(); 413 if (++completed == tests) port.close();
414 }); 414 });
415 for (var i = 0; i < tests; i++) { 415 for (var i = 0; i < tests; i++) {
416 new SocketClose.start(i, port.toSendPort()); 416 new SocketClose.start(i, port.toSendPort());
417 } 417 }
418 } 418 }
OLDNEW
« no previous file with comments | « tests/standalone/io/socket_close_test.dart ('k') | tests/standalone/io/test_extension_fail_tester.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698