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

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

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments 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 unified diff | Download patch | Annotate | Revision Log
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 // Test socket close events. 10 // Test socket close events.
11 11
12 import "package:expect/expect.dart";
13 import 'dart:async'; 12 import 'dart:async';
14 import 'dart:io'; 13 import 'dart:io';
15 import 'dart:isolate'; 14 import 'dart:isolate';
16 15
16 import "package:async_helper/async_helper.dart";
17 import "package:expect/expect.dart";
18
17 const SERVERSHUTDOWN = -1; 19 const SERVERSHUTDOWN = -1;
18 const ITERATIONS = 10; 20 const ITERATIONS = 10;
19 21
20 22
21 class SocketClose { 23 class SocketClose {
22 24
23 SocketClose.start(this._mode, this._donePort) 25 SocketClose.start(this._mode, this._done)
24 : _receivePort = new ReceivePort(), 26 : _receivePort = new ReceivePort(),
25 _sendPort = null, 27 _sendPort = null,
26 _readBytes = 0, 28 _readBytes = 0,
27 _dataEvents = 0, 29 _dataEvents = 0,
28 _closeEvents = 0, 30 _closeEvents = 0,
29 _errorEvents = 0, 31 _errorEvents = 0,
30 _iterations = 0 { 32 _iterations = 0 {
31 _sendPort = spawnFunction(startSocketCloseServer); 33 _sendPort = spawnFunction(startSocketCloseServer);
32 initialize(); 34 initialize();
33 } 35 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 _receivePort.receive((var message, SendPort replyTo) { 145 _receivePort.receive((var message, SendPort replyTo) {
144 _port = message; 146 _port = message;
145 proceed(); 147 proceed();
146 }); 148 });
147 _sendPort.send(_mode, _receivePort.toSendPort()); 149 _sendPort.send(_mode, _receivePort.toSendPort());
148 } 150 }
149 151
150 void shutdown() { 152 void shutdown() {
151 _sendPort.send(SERVERSHUTDOWN, _receivePort.toSendPort()); 153 _sendPort.send(SERVERSHUTDOWN, _receivePort.toSendPort());
152 _receivePort.receive((message, ignore) { 154 _receivePort.receive((message, ignore) {
153 _donePort.send(null); 155 _done();
154 _receivePort.close(); 156 _receivePort.close();
155 }); 157 });
156 158
157 switch (_mode) { 159 switch (_mode) {
158 case 0: 160 case 0:
159 case 1: 161 case 1:
160 Expect.equals(0, _dataEvents); 162 Expect.equals(0, _dataEvents);
161 Expect.equals(ITERATIONS, _closeEvents); 163 Expect.equals(ITERATIONS, _closeEvents);
162 break; 164 break;
163 case 2: 165 case 2:
(...skipping 20 matching lines...) Expand all
184 int _port; 186 int _port;
185 ReceivePort _receivePort; 187 ReceivePort _receivePort;
186 SendPort _sendPort; 188 SendPort _sendPort;
187 List<int> _buffer; 189 List<int> _buffer;
188 int _readBytes; 190 int _readBytes;
189 int _dataEvents; 191 int _dataEvents;
190 int _closeEvents; 192 int _closeEvents;
191 int _errorEvents; 193 int _errorEvents;
192 int _iterations; 194 int _iterations;
193 int _mode; 195 int _mode;
194 SendPort _donePort; 196 Function _done;
195 } 197 }
196 198
197 199
198 class ConnectionData { 200 class ConnectionData {
199 ConnectionData(Socket this.connection) : readBytes = 0; 201 ConnectionData(Socket this.connection) : readBytes = 0;
200 Socket connection; 202 Socket connection;
201 int readBytes; 203 int readBytes;
202 } 204 }
203 205
204 206
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 main() { 371 main() {
370 // Run the close test in these different "modes". 372 // Run the close test in these different "modes".
371 // 0: Client closes without sending at all. 373 // 0: Client closes without sending at all.
372 // 1: Client sends and destroys. 374 // 1: Client sends and destroys.
373 // 2: Client sends. Server destroys. 375 // 2: Client sends. Server destroys.
374 // 3: Client sends. Server responds and destroys. 376 // 3: Client sends. Server responds and destroys.
375 // 4: Client sends and half-closes. Server responds and destroys. 377 // 4: Client sends and half-closes. Server responds and destroys.
376 // 5: Client sends. Server responds and half closes. 378 // 5: Client sends. Server responds and half closes.
377 // 6: Client sends and half-closes. Server responds and half closes. 379 // 6: Client sends and half-closes. Server responds and half closes.
378 var tests = 7; 380 var tests = 7;
379 var port = new ReceivePort();
380 var completed = 0;
381 port.receive((message, ignore) {
382 if (++completed == tests) port.close();
383 });
384 for (var i = 0; i < tests; i++) { 381 for (var i = 0; i < tests; i++) {
385 new SocketClose.start(i, port.toSendPort()); 382 asyncStart();
383 new SocketClose.start(i, asyncEnd);
386 } 384 }
387 } 385 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_socket_bad_data_test.dart ('k') | tests/standalone/io/socket_exception_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698