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 12 matching lines...) Expand all Loading... |
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("localhost", 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().then((server) { |
(...skipping 10 matching lines...) Expand all Loading... |
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("localhost", 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().then((server) { |
74 int closed = 0; | 74 int closed = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
88 }); | 88 }); |
89 request.response.done | 89 request.response.done |
90 .catchError((_) {}) | 90 .catchError((_) {}) |
91 .whenComplete(() { | 91 .whenComplete(() { |
92 check(); | 92 check(); |
93 timer.cancel(); | 93 timer.cancel(); |
94 }); | 94 }); |
95 }); | 95 }); |
96 var client = new HttpClient(); | 96 var client = new HttpClient(); |
97 for (int i = 0; i < connections; i++) { | 97 for (int i = 0; i < connections; i++) { |
98 client.get("localhost", server.port, "/") | 98 client.get("127.0.0.1", server.port, "/") |
99 .then((request) => request.close()) | 99 .then((request) => request.close()) |
100 .then((response) { | 100 .then((response) { |
101 // Ensure we don't accept the response until we have send the entire | 101 // Ensure we don't accept the response until we have send the entire |
102 // request. | 102 // request. |
103 var subscription = response.listen((_) {}); | 103 var subscription = response.listen((_) {}); |
104 new Timer(const Duration(milliseconds: 200), () { | 104 new Timer(const Duration(milliseconds: 200), () { |
105 subscription.cancel(); | 105 subscription.cancel(); |
106 check(); | 106 check(); |
107 }); | 107 }); |
108 }); | 108 }); |
109 } | 109 } |
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 |