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

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

Issue 9307082: Fix at least one source of flakiness in SocketCloseTest. (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 | « no previous file | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test socket close events. 5 // Test socket close events.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 final SERVERSHUTDOWN = -1; 9 final SERVERSHUTDOWN = -1;
10 final ITERATIONS = 10; 10 final ITERATIONS = 10;
11 11
12 12
13 class SocketClose { 13 class SocketClose {
14 14
15 SocketClose.start(mode) 15 SocketClose.start(mode)
16 : _receivePort = new ReceivePort(), 16 : _receivePort = new ReceivePort(),
17 _sendPort = null, 17 _sendPort = null,
18 _readBytes = 0,
18 _dataEvents = 0, 19 _dataEvents = 0,
19 _closeEvents = 0, 20 _closeEvents = 0,
20 _errorEvents = 0, 21 _errorEvents = 0,
21 _iterations = 0, 22 _iterations = 0,
22 _mode = mode { 23 _mode = mode {
23 new SocketCloseServer().spawn().then((SendPort port) { 24 new SocketCloseServer().spawn().then((SendPort port) {
24 _sendPort = port; 25 _sendPort = port;
25 start(); 26 start();
26 }); 27 });
27 } 28 }
(...skipping 13 matching lines...) Expand all
41 case 0: 42 case 0:
42 case 1: 43 case 1:
43 case 2: 44 case 2:
44 Expect.fail("No data expected"); 45 Expect.fail("No data expected");
45 break; 46 break;
46 case 3: 47 case 3:
47 case 4: 48 case 4:
48 case 5: 49 case 5:
49 case 6: 50 case 6:
50 List<int> b = new List<int>(100); 51 List<int> b = new List<int>(100);
51 _socket.readList(b, 0, 100); 52 _readBytes += _socket.readList(b, 0, 100);
52 _dataEvents++; 53 if ((_readBytes % 5) == 0) {
54 _dataEvents++;
55 }
53 break; 56 break;
54 default: 57 default:
55 Expect.fail("Unknown test mode"); 58 Expect.fail("Unknown test mode");
56 } 59 }
57 } 60 }
58 61
59 void closeHandler() { 62 void closeHandler() {
60 _closeEvents++; 63 _closeEvents++;
61 switch (_mode) { 64 switch (_mode) {
62 case 0: 65 case 0:
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 Expect.fail("Unknown test mode"); 170 Expect.fail("Unknown test mode");
168 } 171 }
169 Expect.equals(0, _errorEvents); 172 Expect.equals(0, _errorEvents);
170 } 173 }
171 174
172 int _port; 175 int _port;
173 ReceivePort _receivePort; 176 ReceivePort _receivePort;
174 SendPort _sendPort; 177 SendPort _sendPort;
175 Socket _socket; 178 Socket _socket;
176 List<int> _buffer; 179 List<int> _buffer;
180 int _readBytes;
177 int _dataEvents; 181 int _dataEvents;
178 int _closeEvents; 182 int _closeEvents;
179 int _errorEvents; 183 int _errorEvents;
180 int _iterations; 184 int _iterations;
181 int _mode; 185 int _mode;
182 } 186 }
183 187
184 class SocketCloseServer extends Isolate { 188 class SocketCloseServer extends Isolate {
185 189
186 static final HOST = "127.0.0.1"; 190 static final HOST = "127.0.0.1";
187 191
188 SocketCloseServer() : super() {} 192 SocketCloseServer() : super() {}
189 193
190 void main() { 194 void main() {
191 195
192 void connectionHandler(Socket connection) { 196 void connectionHandler(Socket connection) {
193 197
198 void readBytes(whenFiveBytes) {
199 List<int> b = new List<int>(100);
200 _readBytes += connection.readList(b, 0, 100);
201 if ((_readBytes % 5) == 0) {
202 whenFiveBytes();
203 }
204 }
205
194 void dataHandler() { 206 void dataHandler() {
195 _dataEvents++; 207 _dataEvents++;
196 switch (_mode) { 208 switch (_mode) {
197 case 0: 209 case 0:
198 Expect.fail("No data expected"); 210 Expect.fail("No data expected");
199 break; 211 break;
200 case 1: 212 case 1:
201 List<int> b = new List<int>(100); 213 readBytes(() { });
202 connection.readList(b, 0, 100);
203 break; 214 break;
204 case 2: 215 case 2:
205 List<int> b = new List<int>(100); 216 readBytes(() {
206 connection.readList(b, 0, 100); 217 connection.close();
207 connection.close(); 218 });
208 break; 219 break;
209 case 3: 220 case 3:
210 List<int> b = new List<int>(100); 221 readBytes(() {
211 connection.readList(b, 0, 100); 222 connection.writeList("Hello".charCodes(), 0, 5);
212 connection.writeList("Hello".charCodes(), 0, 5); 223 connection.close();
213 connection.close(); 224 });
214 break; 225 break;
215 case 4: 226 case 4:
216 List<int> b = new List<int>(100); 227 readBytes(() {
217 connection.readList(b, 0, 100); 228 connection.writeList("Hello".charCodes(), 0, 5);
218 connection.writeList("Hello".charCodes(), 0, 5); 229 });
219 break; 230 break;
220 case 5: 231 case 5:
221 case 6: 232 case 6:
222 List<int> b = new List<int>(100); 233 readBytes(() {
223 connection.readList(b, 0, 100); 234 connection.writeList("Hello".charCodes(), 0, 5);
224 connection.writeList("Hello".charCodes(), 0, 5); 235 connection.close(true);
225 connection.close(true); 236 });
226 break; 237 break;
227 default: 238 default:
228 Expect.fail("Unknown test mode"); 239 Expect.fail("Unknown test mode");
229 } 240 }
230 } 241 }
231 242
232 void closeHandler() { 243 void closeHandler() {
233 _closeEvents++; 244 _closeEvents++;
234 connection.close(); 245 connection.close();
235 } 246 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 Expect.equals(0, _errorEvents); 295 Expect.equals(0, _errorEvents);
285 _server.close(); 296 _server.close();
286 this.port.close(); 297 this.port.close();
287 } else { 298 } else {
288 new Timer(waitForResult, 100); 299 new Timer(waitForResult, 100);
289 } 300 }
290 } 301 }
291 302
292 this.port.receive((message, SendPort replyTo) { 303 this.port.receive((message, SendPort replyTo) {
293 if (message != SERVERSHUTDOWN) { 304 if (message != SERVERSHUTDOWN) {
305 _readBytes = 0;
294 _errorEvents = 0; 306 _errorEvents = 0;
295 _dataEvents = 0; 307 _dataEvents = 0;
296 _closeEvents = 0; 308 _closeEvents = 0;
297 _iterations = 0; 309 _iterations = 0;
298 _mode = message; 310 _mode = message;
299 _server = new ServerSocket(HOST, 0, 10); 311 _server = new ServerSocket(HOST, 0, 10);
300 Expect.equals(true, _server !== null); 312 Expect.equals(true, _server !== null);
301 _server.connectionHandler = connectionHandler; 313 _server.connectionHandler = connectionHandler;
302 _server.errorHandler = errorHandlerServer; 314 _server.errorHandler = errorHandlerServer;
303 replyTo.send(_server.port, null); 315 replyTo.send(_server.port, null);
304 } else { 316 } else {
305 new Timer(waitForResult, 0); 317 new Timer(waitForResult, 0);
306 } 318 }
307 }); 319 });
308 } 320 }
309 321
310 ServerSocket _server; 322 ServerSocket _server;
323 int _readBytes;
311 int _errorEvents; 324 int _errorEvents;
312 int _dataEvents; 325 int _dataEvents;
313 int _closeEvents; 326 int _closeEvents;
314 int _iterations; 327 int _iterations;
315 int _mode; 328 int _mode;
316 } 329 }
317 330
318 331
319 main() { 332 main() {
320 // Run the close test in these different "modes". 333 // Run the close test in these different "modes".
321 // 0: Client closes without sending at all. 334 // 0: Client closes without sending at all.
322 // 1: Client sends and closes. 335 // 1: Client sends and closes.
323 // 2: Client sends. Server closes. 336 // 2: Client sends. Server closes.
324 // 3: Client sends. Server responds and closes. 337 // 3: Client sends. Server responds and closes.
325 // 4: Client sends and half-closes. Server responds and closes. 338 // 4: Client sends and half-closes. Server responds and closes.
326 // 5: Client sends. Server responds and half closes. 339 // 5: Client sends. Server responds and half closes.
327 // 6: Client sends and half-closes. Server responds and half closes. 340 // 6: Client sends and half-closes. Server responds and half closes.
328 new SocketClose.start(0); 341 new SocketClose.start(0);
329 new SocketClose.start(1); 342 new SocketClose.start(1);
330 new SocketClose.start(2); 343 new SocketClose.start(2);
331 new SocketClose.start(3); 344 new SocketClose.start(3);
332 new SocketClose.start(4); 345 new SocketClose.start(4);
333 new SocketClose.start(5); 346 new SocketClose.start(5);
334 new SocketClose.start(6); 347 new SocketClose.start(6);
335 } 348 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698