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

Side by Side 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: Addressed review comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5
6 #import("dart:isolate");
7 #import("dart:io");
8
9 void test1(int totalConnections) {
10 // Server which just closes immediately.
11 HttpServer server = new HttpServer();
12 server.listen("127.0.0.1", 0, totalConnections);
13 server.onRequest = (HttpRequest request, HttpResponse response) {
14 response.outputStream.close();
15 };
16
17 int count = 0;
18 HttpClient client = new HttpClient();
19 for (int i = 0; i < totalConnections; i++) {
20 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
21 conn.onRequest = (HttpClientRequest request) {
22 request.outputStream.close();
23 };
24 conn.onResponse = (HttpClientResponse response) {
25 count++;
26 if (count == totalConnections) {
27 client.shutdown();
28 server.close();
29 }
30 };
31 }
32 }
33
34
35 void test2(int totalConnections) {
36 // Server which responds without waiting for request body.
37 HttpServer server = new HttpServer();
38 server.listen("127.0.0.1", 0, totalConnections);
39 server.onRequest = (HttpRequest request, HttpResponse response) {
40 response.writeString("!dlrow ,olleH");
41 response.outputStream.close();
42 };
43
44 int count = 0;
45 HttpClient client = new HttpClient();
46 for (int i = 0; i < totalConnections; i++) {
47 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
48 conn.onRequest = (HttpClientRequest request) {
49 request.writeString("Hello, world!");
50 request.outputStream.close();
51 };
52 conn.onResponse = (HttpClientResponse response) {
53 count++;
54 if (count == totalConnections) {
55 client.shutdown();
56 server.close();
57 }
58 };
59 }
60 }
61
62
63 void test3(int totalConnections) {
64 // Server which responds when request body has been received.
65 HttpServer server = new HttpServer();
66 server.listen("127.0.0.1", 0, totalConnections);
67 server.onRequest = (HttpRequest request, HttpResponse response) {
68 request.inputStream.onClosed = () {
69 response.writeString("!dlrow ,olleH");
70 response.outputStream.close();
71 };
72 };
73
74 int count = 0;
75 HttpClient client = new HttpClient();
76 for (int i = 0; i < totalConnections; i++) {
77 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
78 conn.onRequest = (HttpClientRequest request) {
79 request.writeString("Hello, world!");
80 request.outputStream.close();
81 };
82 conn.onResponse = (HttpClientResponse response) {
83 count++;
84 if (count == totalConnections) {
85 client.shutdown();
86 server.close();
87 }
88 };
89 }
90 }
91
92
93 void main() {
94 test1(1);
95 test1(10);
96 test2(1);
97 test2(10);
98 test3(1);
99 test3(10);
100 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698