Chromium Code Reviews| Index: tests/standalone/src/SocketStreamCloseTest.dart |
| diff --git a/tests/standalone/src/SocketStreamCloseTest.dart b/tests/standalone/src/SocketStreamCloseTest.dart |
| index ed788c5e420b1edaac576809043ddd621320dfd7..a5624b5afb06de7d0de8731dfc2e1ad81d67a5c0 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,11 @@ class SocketClose { |
| case 4: |
| case 5: |
| case 6: |
| - List<int> b = new List<int>(100); |
| - _socket.readList(b, 0, 100); |
| - _dataEvents++; |
| + var read = _socket.inputStream.read(); |
| + _readBytes += read.length; |
| + if ((_readBytes % 5) == 0) { |
| + _dataEvents++; |
| + } |
| break; |
| default: |
| Expect.fail("Unknown test mode"); |
| @@ -100,8 +108,10 @@ 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: |
| @@ -109,14 +119,18 @@ class SocketClose { |
| break; |
| case 4: |
| _socket.outputStream.write("Hello".charCodes()); |
| - _socket.outputStream.close(); |
| + _socket.outputStream.noPendingWriteHandler = () { |
| + _socket.outputStream.close(); |
| + }; |
| break; |
| case 5: |
| _socket.outputStream.write("Hello".charCodes()); |
| break; |
| case 6: |
| _socket.outputStream.write("Hello".charCodes()); |
| - _socket.outputStream.close(); |
| + _socket.outputStream.noPendingWriteHandler = () { |
| + _socket.outputStream.close(); |
| + }; |
| break; |
| default: |
| Expect.fail("Unknown test mode"); |
| @@ -144,7 +158,7 @@ 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); |
| @@ -168,6 +182,7 @@ class SocketClose { |
| SendPort _sendPort; |
| Socket _socket; |
| List<int> _buffer; |
| + int _readBytes; |
| int _dataEvents; |
| int _closeEvents; |
| int _errorEvents; |
| @@ -185,34 +200,53 @@ 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()); |
|
Søren Gjesse
2012/02/09 20:19:42
Maybe we should add two more cases (variants of 3
Mads Ager (google)
2012/02/10 06:56:48
Done.
|
| + connection.outputStream.noPendingWriteHandler = () { |
| + print("connection.inputStream.close();"); |
|
Søren Gjesse
2012/02/09 20:19:42
Debug print.
Mads Ager (google)
2012/02/10 06:56:48
Done.
|
| + connection.inputStream.close(); |
| + }; |
| + }); |
| break; |
| case 4: |
| - connection.inputStream.read(); |
| - connection.outputStream.write("Hello".charCodes()); |
| + readBytes(() { |
| + _dataEvents++; |
| + connection.outputStream.write("Hello".charCodes()); |
| + }); |
| break; |
| case 5: |
| case 6: |
| - connection.inputStream.read(); |
| - connection.outputStream.write("Hello".charCodes()); |
| - connection.outputStream.close(); |
| + readBytes(() { |
| + _dataEvents++; |
| + connection.outputStream.write("Hello".charCodes()); |
| + connection.outputStream.noPendingWriteHandler = () { |
| + connection.outputStream.close(); |
| + }; |
| + }); |
| break; |
| default: |
| Expect.fail("Unknown test mode"); |
| @@ -221,7 +255,7 @@ class SocketCloseServer extends Isolate { |
| void closeHandler() { |
| _closeEvents++; |
| - connection.close(); |
| + connection.outputStream.close(); |
| } |
| void errorHandler() { |
| @@ -279,6 +313,7 @@ class SocketCloseServer extends Isolate { |
| this.port.receive((message, SendPort replyTo) { |
| if (message != SERVERSHUTDOWN) { |
| + _readBytes = 0; |
| _errorEvents = 0; |
| _dataEvents = 0; |
| _closeEvents = 0; |
| @@ -296,6 +331,7 @@ class SocketCloseServer extends Isolate { |
| } |
| ServerSocket _server; |
| + int _readBytes; |
| int _errorEvents; |
| int _dataEvents; |
| int _closeEvents; |