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

Unified Diff: tests/standalone/src/io/HttpServerTest.dart

Issue 9965053: Add a new attachTo method to HttpServer, for using an existing ServerSocket. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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
« runtime/bin/http_impl.dart ('K') | « runtime/bin/http_impl.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/io/HttpServerTest.dart
===================================================================
--- tests/standalone/src/io/HttpServerTest.dart (revision 0)
+++ tests/standalone/src/io/HttpServerTest.dart (revision 0)
@@ -0,0 +1,64 @@
+// Copyright (c) 2012, 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.
+
+#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");
+ };
+
+ void test(void onDone()) {
+ HttpServer server = new HttpServer();
+ Expect.equals(-1, server.port);
+
+ ReceivePort serverPort = new ReceivePort();
+ server.onRequest = (HttpRequest request, HttpResponse response) {
+ request.inputStream.onClosed = () {
+ response.outputStream.close();
+ server.close();
+ Expect.equals(-1, server.port);
+ serverPort.close();
+ onDone();
+ };
+ };
+
+ 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();
+ };
+ };
+ conn.onError = (Exception e) {
+ Expect.fail("Unexpected error in Http Client");
+ };
+ };
+
+ // Test two connection after each other.
+ test(() {
+ test(() {
+ socket.close();
+ });
+ });
+}
+
+void main() {
+ testListenOn();
+}
« runtime/bin/http_impl.dart ('K') | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698