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

Side by Side Diff: tests/standalone/src/SocketStreamCloseTest.dart

Issue 9368058: Revert "Fix potential flakiness of SocketStreamCloseTest." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « tests/standalone/src/SocketCloseTest.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 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9 //
10 // Test socket close events. 5 // Test socket close events.
11 6
12 #import("dart:io"); 7 #import("dart:io");
13 8
14 final SERVERSHUTDOWN = -1; 9 final SERVERSHUTDOWN = -1;
15 final ITERATIONS = 10; 10 final ITERATIONS = 10;
16 11
17 12
18 class SocketClose { 13 class SocketClose {
19 14
20 SocketClose.start(mode) 15 SocketClose.start(mode)
21 : _receivePort = new ReceivePort(), 16 : _receivePort = new ReceivePort(),
22 _sendPort = null, 17 _sendPort = null,
23 _readBytes = 0,
24 _dataEvents = 0, 18 _dataEvents = 0,
25 _closeEvents = 0, 19 _closeEvents = 0,
26 _errorEvents = 0, 20 _errorEvents = 0,
27 _iterations = 0, 21 _iterations = 0,
28 _mode = mode { 22 _mode = mode {
29 new SocketCloseServer().spawn().then((SendPort port) { 23 new SocketCloseServer().spawn().then((SendPort port) {
30 _sendPort = port; 24 _sendPort = port;
31 start(); 25 start();
32 }); 26 });
33 } 27 }
(...skipping 12 matching lines...) Expand all
46 switch (_mode) { 40 switch (_mode) {
47 case 0: 41 case 0:
48 case 1: 42 case 1:
49 case 2: 43 case 2:
50 Expect.fail("No data expected"); 44 Expect.fail("No data expected");
51 break; 45 break;
52 case 3: 46 case 3:
53 case 4: 47 case 4:
54 case 5: 48 case 5:
55 case 6: 49 case 6:
56 case 7: 50 List<int> b = new List<int>(100);
57 case 8: 51 _socket.readList(b, 0, 100);
58 var read = _socket.inputStream.read(); 52 _dataEvents++;
59 _readBytes += read.length;
60 if ((_readBytes % 5) == 0) {
61 _dataEvents++;
62 }
63 break; 53 break;
64 default: 54 default:
65 Expect.fail("Unknown test mode"); 55 Expect.fail("Unknown test mode");
66 } 56 }
67 } 57 }
68 58
69 void closeHandler() { 59 void closeHandler() {
70 _closeEvents++; 60 _closeEvents++;
71 switch (_mode) { 61 switch (_mode) {
72 case 0: 62 case 0:
73 case 1: 63 case 1:
74 break; 64 break;
75 case 2: 65 case 2:
76 case 3: 66 case 3:
77 case 4:
78 _socket.outputStream.close(); 67 _socket.outputStream.close();
79 proceed(); 68 proceed();
80 break; 69 break;
70 case 4:
71 proceed();
72 break;
81 case 5: 73 case 5:
74 _socket.outputStream.close();
82 proceed(); 75 proceed();
83 break; 76 break;
84 case 6: 77 case 6:
85 _socket.outputStream.close();
86 proceed();
87 break;
88 case 7:
89 case 8:
90 proceed(); 78 proceed();
91 break; 79 break;
92 default: 80 default:
93 Expect.fail("Unknown test mode"); 81 Expect.fail("Unknown test mode");
94 } 82 }
95 } 83 }
96 84
97 void errorHandler() { 85 void errorHandler() {
98 _errorEvents++; 86 _errorEvents++;
99 _socket.close(); 87 _socket.close();
100 } 88 }
101 89
102 void connectHandler() { 90 void connectHandler() {
103 _socket.inputStream.dataHandler = dataHandler; 91 _socket.inputStream.dataHandler = dataHandler;
104 _socket.inputStream.closeHandler = closeHandler; 92 _socket.inputStream.closeHandler = closeHandler;
105 _socket.errorHandler = errorHandler; 93 _socket.errorHandler = errorHandler;
106 94
107 _iterations++; 95 _iterations++;
108 switch (_mode) { 96 switch (_mode) {
109 case 0: 97 case 0:
110 _socket.inputStream.close(); 98 _socket.inputStream.close();
111 proceed(); 99 proceed();
112 break; 100 break;
113 case 1: 101 case 1:
114 _socket.outputStream.write("Hello".charCodes()); 102 _socket.outputStream.write("Hello".charCodes());
115 _socket.outputStream.noPendingWriteHandler = () { 103 _socket.inputStream.close();
116 _socket.inputStream.close(); 104 proceed();
117 proceed();
118 };
119 break; 105 break;
120 case 2: 106 case 2:
121 case 3: 107 case 3:
108 _socket.outputStream.write("Hello".charCodes());
109 break;
122 case 4: 110 case 4:
123 _socket.outputStream.write("Hello".charCodes()); 111 _socket.outputStream.write("Hello".charCodes());
112 _socket.outputStream.close();
124 break; 113 break;
125 case 5: 114 case 5:
126 _socket.outputStream.write("Hello".charCodes()); 115 _socket.outputStream.write("Hello".charCodes());
127 _socket.outputStream.noPendingWriteHandler = () {
128 _socket.outputStream.close();
129 };
130 break; 116 break;
131 case 6: 117 case 6:
132 _socket.outputStream.write("Hello".charCodes()); 118 _socket.outputStream.write("Hello".charCodes());
133 break; 119 _socket.outputStream.close();
134 case 7:
135 case 8:
136 _socket.outputStream.write("Hello".charCodes());
137 _socket.outputStream.noPendingWriteHandler = () {
138 _socket.outputStream.close();
139 };
140 break; 120 break;
141 default: 121 default:
142 Expect.fail("Unknown test mode"); 122 Expect.fail("Unknown test mode");
143 } 123 }
144 } 124 }
145 125
146 _socket = new Socket(SocketCloseServer.HOST, _port); 126 _socket = new Socket(SocketCloseServer.HOST, _port);
147 Expect.equals(true, _socket !== null); 127 Expect.equals(true, _socket !== null);
148 _socket.connectHandler = connectHandler; 128 _socket.connectHandler = connectHandler;
149 } 129 }
150 130
151 void start() { 131 void start() {
152 _receivePort.receive((var message, SendPort replyTo) { 132 _receivePort.receive((var message, SendPort replyTo) {
153 _port = message; 133 _port = message;
154 proceed(); 134 proceed();
155 }); 135 });
156 _sendPort.send(_mode, _receivePort.toSendPort()); 136 _sendPort.send(_mode, _receivePort.toSendPort());
157 } 137 }
158 138
159 void shutdown() { 139 void shutdown() {
160 _sendPort.send(SERVERSHUTDOWN, _receivePort.toSendPort()); 140 _sendPort.send(SERVERSHUTDOWN, _receivePort.toSendPort());
161 _receivePort.close(); 141 _receivePort.close();
162 142
163 switch (_mode) { 143 switch (_mode) {
164 case 0: 144 case 0:
165 case 1: 145 case 1:
166 Expect.equals(0, _dataEvents); 146 Expect.equals(0, _dataEvents);
167 Expect.equals(ITERATIONS, _closeEvents); 147 Expect.equals(10, _closeEvents);
168 break; 148 break;
169 case 2: 149 case 2:
170 Expect.equals(0, _dataEvents); 150 Expect.equals(0, _dataEvents);
171 Expect.equals(ITERATIONS, _closeEvents); 151 Expect.equals(ITERATIONS, _closeEvents);
172 break; 152 break;
173 case 3: 153 case 3:
154 case 4:
155 case 5:
156 case 6:
174 Expect.equals(ITERATIONS, _dataEvents); 157 Expect.equals(ITERATIONS, _dataEvents);
175 Expect.equals(ITERATIONS, _closeEvents); 158 Expect.equals(ITERATIONS, _closeEvents);
176 break; 159 break;
177 case 4:
178 Expect.equals(ITERATIONS, _closeEvents);
179 break;
180 case 5:
181 case 6:
182 case 7:
183 case 8:
184 Expect.equals(ITERATIONS, _dataEvents);
185 Expect.equals(ITERATIONS, _closeEvents);
186 break;
187 default: 160 default:
188 Expect.fail("Unknown test mode"); 161 Expect.fail("Unknown test mode");
189 } 162 }
190 Expect.equals(0, _errorEvents); 163 Expect.equals(0, _errorEvents);
191 } 164 }
192 165
193 int _port; 166 int _port;
194 ReceivePort _receivePort; 167 ReceivePort _receivePort;
195 SendPort _sendPort; 168 SendPort _sendPort;
196 Socket _socket; 169 Socket _socket;
197 List<int> _buffer; 170 List<int> _buffer;
198 int _readBytes;
199 int _dataEvents; 171 int _dataEvents;
200 int _closeEvents; 172 int _closeEvents;
201 int _errorEvents; 173 int _errorEvents;
202 int _iterations; 174 int _iterations;
203 int _mode; 175 int _mode;
204 } 176 }
205 177
206 class SocketCloseServer extends Isolate { 178 class SocketCloseServer extends Isolate {
207 179
208 static final HOST = "127.0.0.1"; 180 static final HOST = "127.0.0.1";
209 181
210 SocketCloseServer() : super() {} 182 SocketCloseServer() : super() {}
211 183
212 void main() { 184 void main() {
213 185
214 void connectionHandler(Socket connection) { 186 void connectionHandler(Socket connection) {
215 187
216 void readBytes(whenFiveBytes) {
217 var read = connection.inputStream.read();
218 _readBytes += read.length;
219 if ((_readBytes % 5) == 0) {
220 whenFiveBytes();
221 }
222 }
223
224 void dataHandler() { 188 void dataHandler() {
189 _dataEvents++;
225 switch (_mode) { 190 switch (_mode) {
226 case 0: 191 case 0:
227 Expect.fail("No data expected"); 192 Expect.fail("No data expected");
228 break; 193 break;
229 case 1: 194 case 1:
230 readBytes(() => _dataEvents++); 195 connection.inputStream.read();
231 break; 196 break;
232 case 2: 197 case 2:
233 readBytes(() { 198 connection.inputStream.read();
234 _dataEvents++; 199 connection.inputStream.close();
235 connection.inputStream.close();
236 });
237 break; 200 break;
238 case 3: 201 case 3:
239 readBytes(() { 202 connection.inputStream.read();
240 _dataEvents++; 203 connection.outputStream.write("Hello".charCodes());
241 connection.outputStream.write("Hello".charCodes()); 204 connection.inputStream.close();
242 connection.outputStream.noPendingWriteHandler = () { 205 //connection.outputStream.close();
243 connection.inputStream.close();
244 };
245 });
246 break; 206 break;
247 case 4: 207 case 4:
248 readBytes(() { 208 connection.inputStream.read();
249 _dataEvents++; 209 connection.outputStream.write("Hello".charCodes());
250 connection.outputStream.write("Hello".charCodes());
251 connection.inputStream.close();
252 });
253 break; 210 break;
254 case 5: 211 case 5:
255 readBytes(() {
256 _dataEvents++;
257 connection.outputStream.write("Hello".charCodes());
258 });
259 break;
260 case 6: 212 case 6:
261 case 7: 213 connection.inputStream.read();
262 readBytes(() { 214 connection.outputStream.write("Hello".charCodes());
263 _dataEvents++; 215 connection.outputStream.close();
264 connection.outputStream.write("Hello".charCodes());
265 connection.outputStream.noPendingWriteHandler = () {
266 connection.outputStream.close();
267 };
268 });
269 break;
270 case 8:
271 readBytes(() {
272 _dataEvents++;
273 connection.outputStream.write("Hello".charCodes());
274 connection.outputStream.close();
275 });
276 break; 216 break;
277 default: 217 default:
278 Expect.fail("Unknown test mode"); 218 Expect.fail("Unknown test mode");
279 } 219 }
280 } 220 }
281 221
282 void closeHandler() { 222 void closeHandler() {
283 _closeEvents++; 223 _closeEvents++;
284 connection.outputStream.close(); 224 connection.close();
285 } 225 }
286 226
287 void errorHandler() { 227 void errorHandler() {
288 Expect.fail("Socket error"); 228 Expect.fail("Socket error");
289 } 229 }
290 230
291 _iterations++; 231 _iterations++;
292 232
293 connection.inputStream.dataHandler = dataHandler; 233 connection.inputStream.dataHandler = dataHandler;
294 connection.inputStream.closeHandler = closeHandler; 234 connection.inputStream.closeHandler = closeHandler;
(...skipping 15 matching lines...) Expand all
310 case 0: 250 case 0:
311 Expect.equals(0, _dataEvents); 251 Expect.equals(0, _dataEvents);
312 Expect.equals(ITERATIONS, _closeEvents); 252 Expect.equals(ITERATIONS, _closeEvents);
313 break; 253 break;
314 case 1: 254 case 1:
315 Expect.equals(ITERATIONS, _dataEvents); 255 Expect.equals(ITERATIONS, _dataEvents);
316 Expect.equals(ITERATIONS, _closeEvents); 256 Expect.equals(ITERATIONS, _closeEvents);
317 break; 257 break;
318 case 2: 258 case 2:
319 case 3: 259 case 3:
320 case 4:
321 Expect.equals(ITERATIONS, _dataEvents); 260 Expect.equals(ITERATIONS, _dataEvents);
322 Expect.equals(ITERATIONS, _closeEvents); 261 Expect.equals(ITERATIONS, _closeEvents);
323 break; 262 break;
263 case 4:
324 case 5: 264 case 5:
325 case 6: 265 case 6:
326 case 7:
327 case 8:
328 Expect.equals(ITERATIONS, _dataEvents); 266 Expect.equals(ITERATIONS, _dataEvents);
329 Expect.equals(ITERATIONS, _closeEvents); 267 Expect.equals(ITERATIONS, _closeEvents);
330 break; 268 break;
331 default: 269 default:
332 Expect.fail("Unknown test mode"); 270 Expect.fail("Unknown test mode");
333 } 271 }
334 Expect.equals(0, _errorEvents); 272 Expect.equals(0, _errorEvents);
335 _server.close(); 273 _server.close();
336 this.port.close(); 274 this.port.close();
337 } else { 275 } else {
338 new Timer(waitForResult, 100); 276 new Timer(waitForResult, 100);
339 } 277 }
340 } 278 }
341 279
342 this.port.receive((message, SendPort replyTo) { 280 this.port.receive((message, SendPort replyTo) {
343 if (message != SERVERSHUTDOWN) { 281 if (message != SERVERSHUTDOWN) {
344 _readBytes = 0;
345 _errorEvents = 0; 282 _errorEvents = 0;
346 _dataEvents = 0; 283 _dataEvents = 0;
347 _closeEvents = 0; 284 _closeEvents = 0;
348 _iterations = 0; 285 _iterations = 0;
349 _mode = message; 286 _mode = message;
350 _server = new ServerSocket(HOST, 0, 10); 287 _server = new ServerSocket(HOST, 0, 10);
351 Expect.equals(true, _server !== null); 288 Expect.equals(true, _server !== null);
352 _server.connectionHandler = connectionHandler; 289 _server.connectionHandler = connectionHandler;
353 _server.errorHandler = errorHandlerServer; 290 _server.errorHandler = errorHandlerServer;
354 replyTo.send(_server.port, null); 291 replyTo.send(_server.port, null);
355 } else { 292 } else {
356 new Timer(waitForResult, 0); 293 new Timer(waitForResult, 0);
357 } 294 }
358 }); 295 });
359 } 296 }
360 297
361 ServerSocket _server; 298 ServerSocket _server;
362 int _readBytes;
363 int _errorEvents; 299 int _errorEvents;
364 int _dataEvents; 300 int _dataEvents;
365 int _closeEvents; 301 int _closeEvents;
366 int _iterations; 302 int _iterations;
367 int _mode; 303 int _mode;
368 } 304 }
369 305
370 306
371 main() { 307 main() {
372 // Run the close test in these different "modes". 308 // Run the close test in these different "modes".
373 // 0: Client closes without sending at all. 309 // 0: Client closes without sending at all.
374 // 1: Client sends and closes. 310 // 1: Client sends and closes.
375 // 2: Client sends. Server closes. 311 // 2: Client sends. Server closes.
376 // 3: Client sends. Server responds and closes. 312 // 3: Client sends. Server responds and closes.
377 // 4: Client sends. Server responds and closes without waiting for everything 313 // 4: Client sends and half-closes. Server responds and closes.
378 // being sent. 314 // 5: Client sends. Server responds and half closes.
379 // 5: Client sends and half-closes. Server responds and closes. 315 // 6: Client sends and half-closes. Server responds and half closes.
380 // 6: Client sends. Server responds and half closes.
381 // 7: Client sends and half-closes. Server responds and half closes.
382 // 8: Client sends and half-closes. Server responds and half closes without
383 // explicitly waiting for everything being sent.
384 new SocketClose.start(0); 316 new SocketClose.start(0);
385 new SocketClose.start(1); 317 new SocketClose.start(1);
386 new SocketClose.start(2); 318 new SocketClose.start(2);
387 new SocketClose.start(3); 319 new SocketClose.start(3);
388 new SocketClose.start(4); 320 new SocketClose.start(4);
389 new SocketClose.start(5); 321 new SocketClose.start(5);
390 new SocketClose.start(6); 322 new SocketClose.start(6);
391 new SocketClose.start(7);
392 new SocketClose.start(8);
393 } 323 }
OLDNEW
« no previous file with comments | « tests/standalone/src/SocketCloseTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698