Index: tests/standalone/io/http_basic_test.dart |
diff --git a/tests/standalone/io/http_basic_test.dart b/tests/standalone/io/http_basic_test.dart |
index 6d9caaf9eeee2aa81b7f63946763156104123a4a..2d7eebdc321c9d17d75081b807731fcf1312702c 100644 |
--- a/tests/standalone/io/http_basic_test.dart |
+++ b/tests/standalone/io/http_basic_test.dart |
@@ -14,39 +14,44 @@ import "dart:io"; |
class TestServerMain { |
TestServerMain() |
: _statusPort = new ReceivePort(), |
- _serverPort = null { |
- _serverPort = spawnFunction(startTestServer); |
- } |
+ _serverPort = null; |
void setServerStartedHandler(void startedCallback(int port)) { |
_startedCallback = startedCallback; |
} |
- void start() { |
+ void start([bool chunkedEncoding = false]) { |
+ ReceivePort receivePort = new ReceivePort(); |
+ var remote = Isolate.spawn(startTestServer, receivePort.sendPort); |
+ receivePort.first.then((port) { |
+ _serverPort = port; |
+ |
+ if (chunkedEncoding) { |
+ // Send chunked encoding message to the server. |
+ port.send( |
+ [new TestServerCommand.chunkedEncoding(), _statusPort.sendPort]); |
+ } |
+ |
+ // Send server start message to the server. |
+ var command = new TestServerCommand.start(); |
+ port.send([command, _statusPort.sendPort]); |
+ }); |
+ |
// Handle status messages from the server. |
- _statusPort.receive((var status, SendPort replyTo) { |
+ _statusPort.listen((var status) { |
if (status.isStarted) { |
_startedCallback(status.port); |
} |
}); |
- // Send server start message to the server. |
- var command = new TestServerCommand.start(); |
- _serverPort.send(command, _statusPort.toSendPort()); |
} |
void close() { |
// Send server stop message to the server. |
- _serverPort.send(new TestServerCommand.stop(), _statusPort.toSendPort()); |
+ _serverPort.send([new TestServerCommand.stop(), _statusPort.sendPort]); |
_statusPort.close(); |
} |
- void chunkedEncoding() { |
- // Send chunked encoding message to the server. |
- _serverPort.send( |
- new TestServerCommand.chunkedEncoding(), _statusPort.toSendPort()); |
- } |
- |
ReceivePort _statusPort; // Port for receiving messages from the server. |
SendPort _serverPort; // Port for sending messages to the server. |
var _startedCallback; |
@@ -90,10 +95,10 @@ class TestServerStatus { |
} |
-void startTestServer() { |
+void startTestServer(SendPort replyTo) { |
var server = new TestServer(); |
server.init(); |
- port.receive(server.dispatch); |
+ replyTo.send(server.dispatchSendPort); |
} |
@@ -151,10 +156,16 @@ class TestServer { |
_requestHandlers["/0123456789"] = _zeroToTenHandler; |
_requestHandlers["/reasonformoving"] = _reasonForMovingHandler; |
_requestHandlers["/host"] = _hostHandler; |
+ _dispatchPort = new ReceivePort(); |
+ _dispatchPort.listen(dispatch); |
} |
- void dispatch(var message, SendPort replyTo) { |
- if (message.isStart) { |
+ SendPort get dispatchSendPort => _dispatchPort.sendPort; |
+ |
+ void dispatch(var message) { |
+ TestServerCommand command = message[0]; |
+ SendPort replyTo = message[1]; |
+ if (command.isStart) { |
try { |
HttpServer.bind("127.0.0.1", 0).then((server) { |
_server = server; |
@@ -164,11 +175,11 @@ class TestServer { |
} catch (e) { |
replyTo.send(new TestServerStatus.error(), null); |
} |
- } else if (message.isStop) { |
+ } else if (command.isStop) { |
_server.close(); |
- port.close(); |
+ _dispatchPort.close(); |
replyTo.send(new TestServerStatus.stopped(), null); |
- } else if (message.isChunkedEncoding) { |
+ } else if (command.isChunkedEncoding) { |
_chunkedEncoding = true; |
} |
} |
@@ -183,6 +194,7 @@ class TestServer { |
} |
HttpServer _server; // HTTP server instance. |
+ ReceivePort _dispatchPort; |
Map _requestHandlers; |
bool _chunkedEncoding = false; |
} |
@@ -259,10 +271,7 @@ void testPOST(bool chunkedEncoding) { |
} |
testServerMain.setServerStartedHandler(runTest); |
- if (chunkedEncoding) { |
- testServerMain.chunkedEncoding(); |
- } |
- testServerMain.start(); |
+ testServerMain.start(chunkedEncoding); |
} |
void test404() { |