| OLD | NEW |
| 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:async"; | 6 import "dart:async"; |
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 }; | 109 }; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 void test4() { | 114 void test4() { |
| 115 var server = new HttpServer(); | 115 var server = new HttpServer(); |
| 116 server.listen("127.0.0.1", 0); | 116 server.listen("127.0.0.1", 0); |
| 117 server.defaultRequestHandler = (var request, var response) { | 117 server.defaultRequestHandler = (var request, var response) { |
| 118 request.inputStream.onClosed = () { | 118 request.inputStream.onClosed = () { |
| 119 new Timer.repeating(100, (timer) { | 119 new Timer.repeating(new Duration(milliseconds: 100), (timer) { |
| 120 if (server.connectionsInfo().total == 0) { | 120 if (server.connectionsInfo().total == 0) { |
| 121 server.close(); | 121 server.close(); |
| 122 timer.cancel(); | 122 timer.cancel(); |
| 123 } | 123 } |
| 124 }); | 124 }); |
| 125 response.outputStream.close(); | 125 response.outputStream.close(); |
| 126 }; | 126 }; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 var client= new HttpClient(); | 129 var client= new HttpClient(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 150 // Create a number of client requests and keep then active. Then | 150 // Create a number of client requests and keep then active. Then |
| 151 // close the client and wait for the server to lose all active | 151 // close the client and wait for the server to lose all active |
| 152 // connections. | 152 // connections. |
| 153 var client= new HttpClient(); | 153 var client= new HttpClient(); |
| 154 for (int i = 0; i < totalConnections; i++) { | 154 for (int i = 0; i < totalConnections; i++) { |
| 155 var conn = client.post("127.0.0.1", server.port, "/"); | 155 var conn = client.post("127.0.0.1", server.port, "/"); |
| 156 conn.onRequest = (req) { req.outputStream.write([0]); }; | 156 conn.onRequest = (req) { req.outputStream.write([0]); }; |
| 157 conn.onError = (e) => Expect.isTrue(e is HttpException); | 157 conn.onError = (e) => Expect.isTrue(e is HttpException); |
| 158 } | 158 } |
| 159 bool clientClosed = false; | 159 bool clientClosed = false; |
| 160 new Timer.repeating(100, (timer) { | 160 new Timer.repeating(new Duration(milliseconds: 100), (timer) { |
| 161 if (!clientClosed) { | 161 if (!clientClosed) { |
| 162 if (server.connectionsInfo().total == totalConnections) { | 162 if (server.connectionsInfo().total == totalConnections) { |
| 163 clientClosed = true; | 163 clientClosed = true; |
| 164 client.shutdown(force: true); | 164 client.shutdown(force: true); |
| 165 } | 165 } |
| 166 } else { | 166 } else { |
| 167 if (server.connectionsInfo().total == 0) { | 167 if (server.connectionsInfo().total == 0) { |
| 168 server.close(); | 168 server.close(); |
| 169 timer.cancel(); | 169 timer.cancel(); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 }); | 172 }); |
| 173 } | 173 } |
| 174 | 174 |
| 175 | 175 |
| 176 void main() { | 176 void main() { |
| 177 test1(1); | 177 test1(1); |
| 178 test1(10); | 178 test1(10); |
| 179 test2(1, 10); | 179 test2(1, 10); |
| 180 test2(10, 10); | 180 test2(10, 10); |
| 181 test2(10, 1000); | 181 test2(10, 1000); |
| 182 test3(1); | 182 test3(1); |
| 183 test3(10); | 183 test3(10); |
| 184 test4(); | 184 test4(); |
| 185 test5(1); | 185 test5(1); |
| 186 test5(10); | 186 test5(10); |
| 187 } | 187 } |
| OLD | NEW |