Index: tests/standalone/io/http_server_test.dart |
diff --git a/tests/standalone/io/http_server_test.dart b/tests/standalone/io/http_server_test.dart |
index 8e7424e5349679676b2759509800fbdee2abaaae..dd6eeace72b6db75013afb23ef3a40064513b865 100644 |
--- a/tests/standalone/io/http_server_test.dart |
+++ b/tests/standalone/io/http_server_test.dart |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
// 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. |
@@ -6,56 +6,53 @@ import "dart:io"; |
import "dart:isolate"; |
void testListenOn() { |
- ServerSocket socket = new ServerSocket("127.0.0.1", 0, 5); |
- |
- socket.onError = (Exception e) { |
- Expect.fail("ServerSocket closed unexpected"); |
- }; |
+ ServerSocket socket; |
+ HttpServer server; |
void test(void onDone()) { |
- HttpServer server = new HttpServer(); |
- Expect.throws(() => server.port); |
- |
- ReceivePort serverPort = new ReceivePort(); |
- server.defaultRequestHandler = |
- (HttpRequest request, HttpResponse response) { |
- request.inputStream.onClosed = () { |
- response.outputStream.close(); |
- serverPort.close(); |
- }; |
- }; |
- |
- server.onError = (Exception e) { |
- Expect.fail("Unexpected error in Http Server: $e"); |
- }; |
- server.listenOn(socket); |
Expect.equals(socket.port, server.port); |
- HttpClient client = new HttpClient(); |
- HttpClientConnection conn = client.get("127.0.0.1", socket.port, "/"); |
- conn.onRequest = (HttpClientRequest request) { |
- request.outputStream.close(); |
- }; |
ReceivePort clientPort = new ReceivePort(); |
- conn.onResponse = (HttpClientResponse response) { |
- response.inputStream.onClosed = () { |
- client.shutdown(); |
- clientPort.close(); |
- server.close(); |
- Expect.throws(() => server.port); |
- onDone(); |
- }; |
- }; |
- conn.onError = (Exception e) { |
- Expect.fail("Unexpected error in Http Client: $e"); |
- }; |
- }; |
+ HttpClient client = new HttpClient(); |
+ client.get("127.0.0.1", socket.port, "/") |
+ .then((request) { |
+ return request.close(); |
+ }) |
+ .then((response) { |
+ response.listen( |
+ (_) {}, |
+ onDone: () { |
+ client.close(); |
+ clientPort.close(); |
+ onDone(); |
+ }); |
+ }) |
+ .catchError((error) { |
+ Expect.fail("Unexpected error in Http Client: $error"); |
+ }); |
+ } |
// Test two connection after each other. |
- test(() { |
+ ServerSocket.bind().then((s) { |
+ socket = s; |
+ server = new HttpServer.listenOn(socket); |
+ ReceivePort serverPort = new ReceivePort(); |
+ server.listen((HttpRequest request) { |
+ request.listen( |
+ (_) {}, |
+ onDone: () { |
+ request.response.close(); |
+ serverPort.close(); |
+ }); |
+ }); |
+ |
test(() { |
- socket.close(); |
+ test(() { |
+ server.close(); |
+ Expect.throws(() => server.port); |
+ socket.close(); |
+ }); |
}); |
}); |
} |