| 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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 11 import "dart:async"; | 11 import "dart:async"; |
| 12 import "dart:io"; | 12 import "dart:io"; |
| 13 import "dart:typed_data"; | 13 import "dart:typed_data"; |
| 14 | 14 |
| 15 | 15 |
| 16 void testClientAndServerCloseNoListen(int connections) { | 16 void testClientAndServerCloseNoListen(int connections) { |
| 17 HttpServer.bind().then((server) { | 17 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 18 int closed = 0; | 18 int closed = 0; |
| 19 server.listen((request) { | 19 server.listen((request) { |
| 20 request.response.close(); | 20 request.response.close(); |
| 21 request.response.done.then((_) { | 21 request.response.done.then((_) { |
| 22 closed++; | 22 closed++; |
| 23 if (closed == connections) { | 23 if (closed == connections) { |
| 24 Expect.equals(0, server.connectionsInfo().active); | 24 Expect.equals(0, server.connectionsInfo().active); |
| 25 Expect.equals(server.connectionsInfo().total, | 25 Expect.equals(server.connectionsInfo().total, |
| 26 server.connectionsInfo().idle); | 26 server.connectionsInfo().idle); |
| 27 server.close(); | 27 server.close(); |
| 28 } | 28 } |
| 29 }); | 29 }); |
| 30 }); | 30 }); |
| 31 var client = new HttpClient(); | 31 var client = new HttpClient(); |
| 32 for (int i = 0; i < connections; i++) { | 32 for (int i = 0; i < connections; i++) { |
| 33 client.get("127.0.0.1", server.port, "/") | 33 client.get("127.0.0.1", server.port, "/") |
| 34 .then((request) => request.close()) | 34 .then((request) => request.close()) |
| 35 .then((response) { | 35 .then((response) { |
| 36 }); | 36 }); |
| 37 } | 37 } |
| 38 }); | 38 }); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 void testClientCloseServerListen(int connections) { | 42 void testClientCloseServerListen(int connections) { |
| 43 HttpServer.bind().then((server) { | 43 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 44 int closed = 0; | 44 int closed = 0; |
| 45 void check() { | 45 void check() { |
| 46 closed++; | 46 closed++; |
| 47 if (closed == connections * 2) { | 47 if (closed == connections * 2) { |
| 48 Expect.equals(0, server.connectionsInfo().active); | 48 Expect.equals(0, server.connectionsInfo().active); |
| 49 Expect.equals(server.connectionsInfo().total, | 49 Expect.equals(server.connectionsInfo().total, |
| 50 server.connectionsInfo().idle); | 50 server.connectionsInfo().idle); |
| 51 server.close(); | 51 server.close(); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 server.listen((request) { | 54 server.listen((request) { |
| 55 request.listen( | 55 request.listen( |
| 56 (_) {}, | 56 (_) {}, |
| 57 onDone: () { | 57 onDone: () { |
| 58 request.response.close(); | 58 request.response.close(); |
| 59 request.response.done.then((_) => check()); | 59 request.response.done.then((_) => check()); |
| 60 }); | 60 }); |
| 61 }); | 61 }); |
| 62 var client = new HttpClient(); | 62 var client = new HttpClient(); |
| 63 for (int i = 0; i < connections; i++) { | 63 for (int i = 0; i < connections; i++) { |
| 64 client.get("127.0.0.1", server.port, "/") | 64 client.get("127.0.0.1", server.port, "/") |
| 65 .then((request) => request.close()) | 65 .then((request) => request.close()) |
| 66 .then((response) => check()); | 66 .then((response) => check()); |
| 67 } | 67 } |
| 68 }); | 68 }); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 void testClientCloseSendingResponse(int connections) { | 72 void testClientCloseSendingResponse(int connections) { |
| 73 HttpServer.bind().then((server) { | 73 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 74 int closed = 0; | 74 int closed = 0; |
| 75 void check() { | 75 void check() { |
| 76 closed++; | 76 closed++; |
| 77 // Wait for both server and client to see the connections as closed. | 77 // Wait for both server and client to see the connections as closed. |
| 78 if (closed == connections * 2) { | 78 if (closed == connections * 2) { |
| 79 Expect.equals(0, server.connectionsInfo().active); | 79 Expect.equals(0, server.connectionsInfo().active); |
| 80 Expect.equals(server.connectionsInfo().total, | 80 Expect.equals(server.connectionsInfo().total, |
| 81 server.connectionsInfo().idle); | 81 server.connectionsInfo().idle); |
| 82 server.close(); | 82 server.close(); |
| 83 } | 83 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 }); | 110 }); |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 void main() { | 114 void main() { |
| 115 testClientAndServerCloseNoListen(10); | 115 testClientAndServerCloseNoListen(10); |
| 116 testClientCloseServerListen(10); | 116 testClientCloseServerListen(10); |
| 117 testClientCloseSendingResponse(10); | 117 testClientCloseSendingResponse(10); |
| 118 } | 118 } |
| 119 | 119 |
| OLD | NEW |