| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
| 7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
| 8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 run(); | 241 run(); |
| 242 }); | 242 }); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 run(); | 245 run(); |
| 246 }); | 246 }); |
| 247 }); | 247 }); |
| 248 }); | 248 }); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void testMaxConnectionsPerHost(int connectionCap, int connections) { |
| 252 asyncStart(); |
| 253 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 254 int handled = 0; |
| 255 server.listen((request) { |
| 256 Expect.isTrue(server.connectionsInfo().total <= connectionCap); |
| 257 request.response.close(); |
| 258 handled++; |
| 259 if (handled == connections) { |
| 260 asyncEnd(); |
| 261 server.close(); |
| 262 } |
| 263 }); |
| 264 |
| 265 var client = new HttpClient(); |
| 266 client.maxConnectionsPerHost = connectionCap; |
| 267 for (int i = 0; i < connections; i++) { |
| 268 asyncStart(); |
| 269 client.get("127.0.0.1", server.port, "/") |
| 270 .then((request) => request.close()) |
| 271 .then((response) { |
| 272 response.listen(null, onDone: () { |
| 273 asyncEnd(); |
| 274 }); |
| 275 }); |
| 276 } |
| 277 }); |
| 278 } |
| 279 |
| 251 | 280 |
| 252 void main() { | 281 void main() { |
| 253 testGetEmptyRequest(); | 282 testGetEmptyRequest(); |
| 254 testGetDataRequest(); | 283 testGetDataRequest(); |
| 255 testGetInvalidHost(); | 284 testGetInvalidHost(); |
| 256 testGetServerClose(); | 285 testGetServerClose(); |
| 257 testGetServerCloseNoKeepAlive(); | 286 testGetServerCloseNoKeepAlive(); |
| 258 testGetServerForceClose(); | 287 testGetServerForceClose(); |
| 259 testGetDataServerForceClose(); | 288 testGetDataServerForceClose(); |
| 260 testOpenEmptyRequest(); | 289 testOpenEmptyRequest(); |
| 261 testOpenUrlEmptyRequest(); | 290 testOpenUrlEmptyRequest(); |
| 262 testNoBuffer(); | 291 testNoBuffer(); |
| 292 testMaxConnectionsPerHost(1, 1); |
| 293 testMaxConnectionsPerHost(1, 10); |
| 294 testMaxConnectionsPerHost(5, 10); |
| 295 testMaxConnectionsPerHost(10, 50); |
| 263 } | 296 } |
| OLD | NEW |