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

Unified Diff: tests/standalone/src/SocketStreamCloseTest.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/src/SocketCloseTest.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/SocketStreamCloseTest.dart
diff --git a/tests/standalone/src/SocketStreamCloseTest.dart b/tests/standalone/src/SocketStreamCloseTest.dart
index ed788c5e420b1edaac576809043ddd621320dfd7..ee8f594f3a0d047eae4e1accaacad1350276da64 100644
--- a/tests/standalone/src/SocketStreamCloseTest.dart
+++ b/tests/standalone/src/SocketStreamCloseTest.dart
@@ -2,6 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
+// VMOptions=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+//
// Test socket close events.
#import("dart:io");
@@ -15,6 +20,7 @@ class SocketClose {
SocketClose.start(mode)
: _receivePort = new ReceivePort(),
_sendPort = null,
+ _readBytes = 0,
_dataEvents = 0,
_closeEvents = 0,
_errorEvents = 0,
@@ -47,9 +53,13 @@ class SocketClose {
case 4:
case 5:
case 6:
- List<int> b = new List<int>(100);
- _socket.readList(b, 0, 100);
- _dataEvents++;
+ case 7:
+ case 8:
+ var read = _socket.inputStream.read();
+ _readBytes += read.length;
+ if ((_readBytes % 5) == 0) {
+ _dataEvents++;
+ }
break;
default:
Expect.fail("Unknown test mode");
@@ -64,17 +74,19 @@ class SocketClose {
break;
case 2:
case 3:
+ case 4:
_socket.outputStream.close();
proceed();
break;
- case 4:
+ case 5:
proceed();
break;
- case 5:
+ case 6:
_socket.outputStream.close();
proceed();
break;
- case 6:
+ case 7:
+ case 8:
proceed();
break;
default:
@@ -100,23 +112,31 @@ class SocketClose {
break;
case 1:
_socket.outputStream.write("Hello".charCodes());
- _socket.inputStream.close();
- proceed();
+ _socket.outputStream.noPendingWriteHandler = () {
+ _socket.inputStream.close();
+ proceed();
+ };
break;
case 2:
case 3:
- _socket.outputStream.write("Hello".charCodes());
- break;
case 4:
_socket.outputStream.write("Hello".charCodes());
- _socket.outputStream.close();
break;
case 5:
_socket.outputStream.write("Hello".charCodes());
+ _socket.outputStream.noPendingWriteHandler = () {
+ _socket.outputStream.close();
+ };
break;
case 6:
_socket.outputStream.write("Hello".charCodes());
- _socket.outputStream.close();
+ break;
+ case 7:
+ case 8:
+ _socket.outputStream.write("Hello".charCodes());
+ _socket.outputStream.noPendingWriteHandler = () {
+ _socket.outputStream.close();
+ };
break;
default:
Expect.fail("Unknown test mode");
@@ -144,16 +164,23 @@ class SocketClose {
case 0:
case 1:
Expect.equals(0, _dataEvents);
- Expect.equals(10, _closeEvents);
+ Expect.equals(ITERATIONS, _closeEvents);
break;
case 2:
Expect.equals(0, _dataEvents);
Expect.equals(ITERATIONS, _closeEvents);
break;
case 3:
+ Expect.equals(ITERATIONS, _dataEvents);
+ Expect.equals(ITERATIONS, _closeEvents);
+ break;
case 4:
+ Expect.equals(ITERATIONS, _closeEvents);
+ break;
case 5:
case 6:
+ case 7:
+ case 8:
Expect.equals(ITERATIONS, _dataEvents);
Expect.equals(ITERATIONS, _closeEvents);
break;
@@ -168,6 +195,7 @@ class SocketClose {
SendPort _sendPort;
Socket _socket;
List<int> _buffer;
+ int _readBytes;
int _dataEvents;
int _closeEvents;
int _errorEvents;
@@ -185,34 +213,66 @@ class SocketCloseServer extends Isolate {
void connectionHandler(Socket connection) {
+ void readBytes(whenFiveBytes) {
+ var read = connection.inputStream.read();
+ _readBytes += read.length;
+ if ((_readBytes % 5) == 0) {
+ whenFiveBytes();
+ }
+ }
+
void dataHandler() {
- _dataEvents++;
switch (_mode) {
case 0:
Expect.fail("No data expected");
break;
case 1:
- connection.inputStream.read();
+ readBytes(() => _dataEvents++);
break;
case 2:
- connection.inputStream.read();
- connection.inputStream.close();
+ readBytes(() {
+ _dataEvents++;
+ connection.inputStream.close();
+ });
break;
case 3:
- connection.inputStream.read();
- connection.outputStream.write("Hello".charCodes());
- connection.inputStream.close();
- //connection.outputStream.close();
+ readBytes(() {
+ _dataEvents++;
+ connection.outputStream.write("Hello".charCodes());
+ connection.outputStream.noPendingWriteHandler = () {
+ connection.inputStream.close();
+ };
+ });
break;
case 4:
- connection.inputStream.read();
- connection.outputStream.write("Hello".charCodes());
+ readBytes(() {
+ _dataEvents++;
+ connection.outputStream.write("Hello".charCodes());
+ connection.inputStream.close();
+ });
break;
case 5:
+ readBytes(() {
+ _dataEvents++;
+ connection.outputStream.write("Hello".charCodes());
+ });
+ break;
case 6:
- connection.inputStream.read();
- connection.outputStream.write("Hello".charCodes());
- connection.outputStream.close();
+ case 7:
+ readBytes(() {
+ _dataEvents++;
+ connection.outputStream.write("Hello".charCodes());
+ connection.outputStream.noPendingWriteHandler = () {
+ connection.outputStream.close();
+ };
+ });
+ break;
+ case 8:
+ readBytes(() {
+ _dataEvents++;
+ connection.outputStream.write("Hello".charCodes());
+ connection.outputStream.close();
+ });
break;
default:
Expect.fail("Unknown test mode");
@@ -221,7 +281,7 @@ class SocketCloseServer extends Isolate {
void closeHandler() {
_closeEvents++;
- connection.close();
+ connection.outputStream.close();
}
void errorHandler() {
@@ -257,12 +317,14 @@ class SocketCloseServer extends Isolate {
break;
case 2:
case 3:
+ case 4:
Expect.equals(ITERATIONS, _dataEvents);
Expect.equals(ITERATIONS, _closeEvents);
break;
- case 4:
case 5:
case 6:
+ case 7:
+ case 8:
Expect.equals(ITERATIONS, _dataEvents);
Expect.equals(ITERATIONS, _closeEvents);
break;
@@ -279,6 +341,7 @@ class SocketCloseServer extends Isolate {
this.port.receive((message, SendPort replyTo) {
if (message != SERVERSHUTDOWN) {
+ _readBytes = 0;
_errorEvents = 0;
_dataEvents = 0;
_closeEvents = 0;
@@ -296,6 +359,7 @@ class SocketCloseServer extends Isolate {
}
ServerSocket _server;
+ int _readBytes;
int _errorEvents;
int _dataEvents;
int _closeEvents;
@@ -310,9 +374,13 @@ main() {
// 1: Client sends and closes.
// 2: Client sends. Server closes.
// 3: Client sends. Server responds and closes.
- // 4: Client sends and half-closes. Server responds and closes.
- // 5: Client sends. Server responds and half closes.
- // 6: Client sends and half-closes. Server responds and half closes.
+ // 4: Client sends. Server responds and closes without waiting for everything
+ // being sent.
+ // 5: Client sends and half-closes. Server responds and closes.
+ // 6: Client sends. Server responds and half closes.
+ // 7: Client sends and half-closes. Server responds and half closes.
+ // 8: Client sends and half-closes. Server responds and half closes without
+ // explicitly waiting for everything being sent.
new SocketClose.start(0);
new SocketClose.start(1);
new SocketClose.start(2);
@@ -320,4 +388,6 @@ main() {
new SocketClose.start(4);
new SocketClose.start(5);
new SocketClose.start(6);
+ new SocketClose.start(7);
+ new SocketClose.start(8);
}
« 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