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

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

Issue 9361034: Fix potential flakiness of SocketStreamCloseTest. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments 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 | « runtime/bin/socket_impl.dart ('k') | tests/standalone/src/SocketStreamCloseTest.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) 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 //
5 // Test socket close events. 10 // Test socket close events.
6 11
7 #import("dart:io"); 12 #import("dart:io");
8 13
9 final SERVERSHUTDOWN = -1; 14 final SERVERSHUTDOWN = -1;
10 final ITERATIONS = 10; 15 final ITERATIONS = 10;
11 16
12 17
13 class SocketClose { 18 class SocketClose {
14 19
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void errorHandler() { 94 void errorHandler() {
90 _errorEvents++; 95 _errorEvents++;
91 _socket.close(); 96 _socket.close();
92 } 97 }
93 98
94 void connectHandler() { 99 void connectHandler() {
95 _socket.dataHandler = dataHandler; 100 _socket.dataHandler = dataHandler;
96 _socket.closeHandler = closeHandler; 101 _socket.closeHandler = closeHandler;
97 _socket.errorHandler = errorHandler; 102 _socket.errorHandler = errorHandler;
98 103
104 void writeHello() {
105 int bytesWritten = 0;
106 while (bytesWritten != 5) {
107 bytesWritten += _socket.writeList("Hello".charCodes(),
108 bytesWritten,
109 5 - bytesWritten);
110 }
111 }
112
99 _iterations++; 113 _iterations++;
100 switch (_mode) { 114 switch (_mode) {
101 case 0: 115 case 0:
102 _socket.close(); 116 _socket.close();
103 proceed(); 117 proceed();
104 break; 118 break;
105 case 1: 119 case 1:
106 int bytesWritten = _socket.writeList("Hello".charCodes(), 0, 5); 120 writeHello();
107 Expect.equals(5, bytesWritten);
108 _socket.close(); 121 _socket.close();
109 proceed(); 122 proceed();
110 break; 123 break;
111 case 2: 124 case 2:
112 case 3: 125 case 3:
113 int bytesWritten = _socket.writeList("Hello".charCodes(), 0, 5); 126 writeHello();
114 Expect.equals(5, bytesWritten);
115 break; 127 break;
116 case 4: 128 case 4:
117 int bytesWritten = _socket.writeList("Hello".charCodes(), 0, 5); 129 writeHello();
118 Expect.equals(5, bytesWritten);
119 _socket.close(true); 130 _socket.close(true);
120 break; 131 break;
121 case 5: 132 case 5:
122 int bytesWritten = _socket.writeList("Hello".charCodes(), 0, 5); 133 writeHello();
123 Expect.equals(5, bytesWritten);
124 break; 134 break;
125 case 6: 135 case 6:
126 int bytesWritten = _socket.writeList("Hello".charCodes(), 0, 5); 136 writeHello();
127 Expect.equals(5, bytesWritten);
128 _socket.close(true); 137 _socket.close(true);
129 break; 138 break;
130 default: 139 default:
131 Expect.fail("Unknown test mode"); 140 Expect.fail("Unknown test mode");
132 } 141 }
133 } 142 }
134 143
135 _socket = new Socket(SocketCloseServer.HOST, _port); 144 _socket = new Socket(SocketCloseServer.HOST, _port);
136 Expect.equals(true, _socket !== null); 145 Expect.equals(true, _socket !== null);
137 _socket.connectHandler = connectHandler; 146 _socket.connectHandler = connectHandler;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 void connectionHandler(Socket connection) { 205 void connectionHandler(Socket connection) {
197 206
198 void readBytes(whenFiveBytes) { 207 void readBytes(whenFiveBytes) {
199 List<int> b = new List<int>(100); 208 List<int> b = new List<int>(100);
200 _readBytes += connection.readList(b, 0, 100); 209 _readBytes += connection.readList(b, 0, 100);
201 if ((_readBytes % 5) == 0) { 210 if ((_readBytes % 5) == 0) {
202 whenFiveBytes(); 211 whenFiveBytes();
203 } 212 }
204 } 213 }
205 214
215 void writeHello() {
216 int bytesWritten = 0;
217 while (bytesWritten != 5) {
218 bytesWritten += connection.writeList("Hello".charCodes(),
219 bytesWritten,
220 5 - bytesWritten);
221 }
222 }
223
206 void dataHandler() { 224 void dataHandler() {
207 _dataEvents++;
208 switch (_mode) { 225 switch (_mode) {
209 case 0: 226 case 0:
210 Expect.fail("No data expected"); 227 Expect.fail("No data expected");
211 break; 228 break;
212 case 1: 229 case 1:
213 readBytes(() { }); 230 readBytes(() { _dataEvents++; });
214 break; 231 break;
215 case 2: 232 case 2:
216 readBytes(() { 233 readBytes(() {
234 _dataEvents++;
217 connection.close(); 235 connection.close();
218 }); 236 });
219 break; 237 break;
220 case 3: 238 case 3:
221 readBytes(() { 239 readBytes(() {
222 connection.writeList("Hello".charCodes(), 0, 5); 240 _dataEvents++;
241 writeHello();
223 connection.close(); 242 connection.close();
224 }); 243 });
225 break; 244 break;
226 case 4: 245 case 4:
227 readBytes(() { 246 readBytes(() {
228 connection.writeList("Hello".charCodes(), 0, 5); 247 _dataEvents++;
248 writeHello();
229 }); 249 });
230 break; 250 break;
231 case 5: 251 case 5:
232 case 6: 252 case 6:
233 readBytes(() { 253 readBytes(() {
234 connection.writeList("Hello".charCodes(), 0, 5); 254 _dataEvents++;
255 writeHello();
235 connection.close(true); 256 connection.close(true);
236 }); 257 });
237 break; 258 break;
238 default: 259 default:
239 Expect.fail("Unknown test mode"); 260 Expect.fail("Unknown test mode");
240 } 261 }
241 } 262 }
242 263
243 void closeHandler() { 264 void closeHandler() {
244 _closeEvents++; 265 _closeEvents++;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // 5: Client sends. Server responds and half closes. 358 // 5: Client sends. Server responds and half closes.
338 // 6: Client sends and half-closes. Server responds and half closes. 359 // 6: Client sends and half-closes. Server responds and half closes.
339 new SocketClose.start(0); 360 new SocketClose.start(0);
340 new SocketClose.start(1); 361 new SocketClose.start(1);
341 new SocketClose.start(2); 362 new SocketClose.start(2);
342 new SocketClose.start(3); 363 new SocketClose.start(3);
343 new SocketClose.start(4); 364 new SocketClose.start(4);
344 new SocketClose.start(5); 365 new SocketClose.start(5);
345 new SocketClose.start(6); 366 new SocketClose.start(6);
346 } 367 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | tests/standalone/src/SocketStreamCloseTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698