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

Side by Side Diff: tests/standalone/io/http_shutdown_test.dart

Issue 11348127: Make HTTP server close sockets when closed in idle state (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « sdk/lib/io/http_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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 5
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 void test1(int totalConnections) { 9 void test1(int totalConnections) {
10 // Server which just closes immediately. 10 // Server which just closes immediately.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 count++; 88 count++;
89 if (count == totalConnections) { 89 if (count == totalConnections) {
90 client.shutdown(); 90 client.shutdown();
91 server.close(); 91 server.close();
92 } 92 }
93 }; 93 };
94 } 94 }
95 } 95 }
96 96
97 97
98 void test4() {
99 var server = new HttpServer();
100 server.listen("127.0.0.1", 0);
101 server.defaultRequestHandler = (var request, var response) {
102 request.inputStream.onClosed = () {
103 new Timer.repeating(100, (timer) {
104 if (server.connectionsInfo().total == 0) {
105 server.close();
106 timer.cancel();
107 }
108 });
109 response.outputStream.close();
110 };
111 };
112
113 var client= new HttpClient();
114 var conn = client.get("127.0.0.1", server.port, "/");
115 conn.onResponse = (var response) {
116 response.inputStream.onClosed = () {
117 client.shutdown();
118 };
119 };
120 }
121
122
123 void test5(int totalConnections) {
124 var server = new HttpServer();
125 server.listen("127.0.0.1", 0, backlog: totalConnections);
126 server.defaultRequestHandler = (var request, var response) {
127 request.inputStream.onClosed = () {
128 response.outputStream.close();
129 };
130 };
131 server.onError = (e) => { };
132
133 // Create a number of client requests and keep then active. Then
134 // close the client and wait for the server to loose all active
Mads Ager (google) 2012/11/19 10:56:57 loose -> lose
135 // connections.
136 var client= new HttpClient();
137 for (int i = 0; i < totalConnections; i++) {
138 var conn = client.post("127.0.0.1", server.port, "/");
139 conn.onRequest = (req) { req.outputStream.write([0]); };
140 }
141 bool clientClosed = false;
142 new Timer.repeating(100, (timer) {
143 if (!clientClosed) {
144 if (server.connectionsInfo().total == totalConnections) {
145 clientClosed = true;
146 client.shutdown();
147 }
148 } else {
149 if (server.connectionsInfo().total == 0) {
150 server.close();
151 timer.cancel();
152 }
153 }
154 });
155 }
156
157
98 void main() { 158 void main() {
99 test1(1); 159 test1(1);
100 test1(10); 160 test1(10);
101 test2(1); 161 test2(1);
102 test2(10); 162 test2(10);
103 test3(1); 163 test3(1);
104 test3(10); 164 test3(10);
165 test4();
166 test5(1);
167 test5(10);
105 } 168 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698