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

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

Issue 9589001: Handle closing of HTTP client and server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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/socket_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/HttpShutdownTest.dart
diff --git a/tests/standalone/src/io/HttpShutdownTest.dart b/tests/standalone/src/io/HttpShutdownTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4532d437e5f9dc18b75c1ca14ea2909294300429
--- /dev/null
+++ b/tests/standalone/src/io/HttpShutdownTest.dart
@@ -0,0 +1,102 @@
+// 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:isolate");
+#import("dart:io");
+
+void test1(int totalConnections) {
+ // Server which just closes immediately.
+ HttpServer server = new HttpServer();
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.onRequest = (HttpRequest request, HttpResponse response) {
+ response.outputStream.close();
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onRequest = (HttpClientRequest request) {
+ request.outputStream.close();
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ }
+}
+
+
+void test2(int totalConnections) {
+ // Server which responds without waiting for request body.
+ HttpServer server = new HttpServer();
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.onRequest = (HttpRequest request, HttpResponse response) {
+ response.writeString("!dlrow ,olleH");
+ response.outputStream.close();
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onRequest = (HttpClientRequest request) {
+ request.keepAlive = false;
+ request.writeString("Hello, world!");
+ request.outputStream.close();
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
Anders Johnsen 2012/03/02 13:48:10 With no keepAlive, maybe remove this line?
Søren Gjesse 2012/03/05 07:03:41 I think it is a bug in the test setting keep alive
+ server.close();
+ }
+ };
+ }
+}
+
+
+void test3(int totalConnections) {
+ // Server which responds when request body has been received.
+ HttpServer server = new HttpServer();
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.onRequest = (HttpRequest request, HttpResponse response) {
+ request.inputStream.onClosed = () {
+ response.writeString("!dlrow ,olleH");
+ response.outputStream.close();
+ };
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onRequest = (HttpClientRequest request) {
+ request.keepAlive = false;
Anders Johnsen 2012/03/02 13:48:10 Ditto.
Søren Gjesse 2012/03/05 07:03:41 Ditto.
+ request.writeString("Hello, world!");
+ request.outputStream.close();
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ }
+}
+
+
+void main() {
+ test1(1);
+ test1(10);
+ test2(1);
+ test2(10);
+ test3(1);
+ test3(10);
+}
« runtime/bin/http_impl.dart ('K') | « runtime/bin/socket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698