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"; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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("localhost", server.port, "/") | 64 client.get("localhost", 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 testClientCloseDelayed(int connections) { | |
73 HttpServer.bind().then((server) { | |
74 int closed = 0; | |
75 void check() { | |
76 closed++; | |
77 // Wait for both server and client to see the connections as closed. | |
78 if (closed == connections * 2) { | |
79 Expect.equals(0, server.connectionsInfo().active); | |
80 Expect.equals(server.connectionsInfo().total, | |
81 server.connectionsInfo().idle); | |
82 server.close(); | |
83 } | |
84 } | |
85 server.listen((request) { | |
86 request.pipe(request.response) | |
87 .then((_) => check()); | |
88 }); | |
89 var client = new HttpClient(); | |
90 for (int i = 0; i < connections; i++) { | |
91 var req; | |
92 client.post("localhost", server.port, "/") | |
93 .then((request) { | |
94 req = request; | |
95 request.writeBytes(new Uint8List(1024)); | |
96 return request.response; | |
97 }) | |
98 .then((response) { | |
99 req.close(); | |
100 // Ensure we don't accept the response until we have send the entire | |
101 // request. | |
102 response.listen( | |
103 (_) {}, | |
104 onDone: () { | |
105 check(); | |
106 }); | |
107 }); | |
108 } | |
109 }); | |
110 } | |
111 | |
112 | |
113 void testClientCloseSendingResponse(int connections) { | 72 void testClientCloseSendingResponse(int connections) { |
114 HttpServer.bind().then((server) { | 73 HttpServer.bind().then((server) { |
115 int closed = 0; | 74 int closed = 0; |
116 void check() { | 75 void check() { |
117 closed++; | 76 closed++; |
118 // 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. |
119 if (closed == connections * 2) { | 78 if (closed == connections * 2) { |
120 Expect.equals(0, server.connectionsInfo().active); | 79 Expect.equals(0, server.connectionsInfo().active); |
121 Expect.equals(server.connectionsInfo().total, | 80 Expect.equals(server.connectionsInfo().total, |
122 server.connectionsInfo().idle); | 81 server.connectionsInfo().idle); |
(...skipping 25 matching lines...) Expand all Loading... |
148 }); | 107 }); |
149 }); | 108 }); |
150 } | 109 } |
151 }); | 110 }); |
152 } | 111 } |
153 | 112 |
154 | 113 |
155 void main() { | 114 void main() { |
156 testClientAndServerCloseNoListen(10); | 115 testClientAndServerCloseNoListen(10); |
157 testClientCloseServerListen(10); | 116 testClientCloseServerListen(10); |
158 testClientCloseDelayed(10); | |
159 testClientCloseSendingResponse(10); | 117 testClientCloseSendingResponse(10); |
160 } | 118 } |
161 | 119 |
OLD | NEW |