Index: tests/standalone/io/http_server_early_server_close_test.dart |
diff --git a/tests/standalone/io/http_server_early_server_close_test.dart b/tests/standalone/io/http_server_early_server_close_test.dart |
index 76092579a13fb429b85920dbef5a83a5161ac3b2..79f12546780e74ab4070d5e5e934efcddd04b613 100644 |
--- a/tests/standalone/io/http_server_early_server_close_test.dart |
+++ b/tests/standalone/io/http_server_early_server_close_test.dart |
@@ -7,39 +7,38 @@ import "dart:io"; |
import "dart:isolate"; |
class Server { |
- Server() { |
- HttpServer server = new HttpServer(); |
- server.listen("127.0.0.1", 0); |
- port = server.port; |
- server.defaultRequestHandler = |
- (HttpRequest request, HttpResponse response) { |
- Timer.run(server.close); |
- }; |
- server.onError = (e) { |
- Expect.fail("No server errors expected: $e"); |
- }; |
+ static Future<int> start() { |
+ return HttpServer.bind("127.0.0.1", 0).then((server) { |
+ server.listen((HttpRequest request) { |
+ Timer.run(server.close); |
+ }, onError: (e) { |
+ Expect.fail("No server errors expected: $e"); |
+ }); |
+ return server.port; |
+ }); |
} |
- int port; |
} |
class Client { |
Client(int port) { |
ReceivePort r = new ReceivePort(); |
HttpClient client = new HttpClient(); |
- HttpClientConnection c = client.get("127.0.0.1", port, "/"); |
- c.onRequest = (HttpClientRequest request) { |
- request.outputStream.close(); |
- }; |
- c.onResponse = (HttpClientResponse response) { |
- Expect.fail("Response should not be given, as not data was returned."); |
- }; |
- c.onError = (e) { |
- r.close(); |
- }; |
+ client.get("127.0.0.1", port, "/") |
+ .then((HttpClientRequest request) { |
+ return request.close(); |
+ }) |
+ .then((HttpClientResponse response) { |
+ Expect.fail( |
+ "Response should not be given, as not data was returned."); |
+ }) |
+ .catchError((e) { |
+ r.close(); |
+ }); |
} |
} |
main() { |
- Server server = new Server(); |
- new Client(server.port); |
+ Server.start().then((port) { |
+ new Client(port); |
+ }); |
} |