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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 client.close(); | 61 client.close(); |
62 asyncEnd(); | 62 asyncEnd(); |
63 }); | 63 }); |
64 } | 64 } |
65 | 65 |
66 void testGetServerClose() { | 66 void testGetServerClose() { |
67 asyncStart(); | 67 asyncStart(); |
68 HttpServer.bind("127.0.0.1", 0).then((server) { | 68 HttpServer.bind("127.0.0.1", 0).then((server) { |
69 server.listen((request) { | 69 server.listen((request) { |
70 server.close(); | 70 server.close(); |
| 71 new Timer(const Duration(milliseconds: 100), () { |
| 72 request.response.close(); |
| 73 }); |
71 }); | 74 }); |
72 | 75 |
73 var client = new HttpClient(); | 76 var client = new HttpClient(); |
| 77 client.get("127.0.0.1", server.port, "/") |
| 78 .then((request) => request.close()) |
| 79 .then((response) => response.drain()) |
| 80 .then((_) => asyncEnd()); |
| 81 }); |
| 82 } |
| 83 |
| 84 void testGetServerCloseNoKeepAlive() { |
| 85 asyncStart(); |
| 86 var client = new HttpClient(); |
| 87 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 88 int port = server.port; |
| 89 server.first.then((request) => request.response.close()); |
| 90 |
| 91 client.get("127.0.0.1", port, "/") |
| 92 .then((request) => request.close()) |
| 93 .then((response) => response.drain()) |
| 94 .then((_) => client.get("127.0.0.1", port, "/")) |
| 95 .then((request) => request.close()) |
| 96 .then((_) => Expect.fail('should not succeed'), onError: (_) {}) |
| 97 .then((_) => asyncEnd()); |
| 98 }); |
| 99 } |
| 100 |
| 101 void testGetServerForceClose() { |
| 102 asyncStart(); |
| 103 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 104 server.listen((request) { |
| 105 server.close(force: true); |
| 106 }); |
| 107 |
| 108 var client = new HttpClient(); |
74 client.get("127.0.0.1", server.port, "/") | 109 client.get("127.0.0.1", server.port, "/") |
75 .then((request) => request.close()) | 110 .then((request) => request.close()) |
76 .then((response) { | 111 .then((response) { |
77 Expect.fail("Request not expected"); | 112 Expect.fail("Request not expected"); |
78 }) | 113 }) |
79 .catchError((error) => asyncEnd(), | 114 .catchError((error) => asyncEnd(), |
80 test: (error) => error is HttpException); | 115 test: (error) => error is HttpException); |
81 }); | 116 }); |
82 } | 117 } |
83 | 118 |
84 void testGetDataServerClose() { | 119 void testGetDataServerForceClose() { |
85 asyncStart(); | 120 asyncStart(); |
86 var completer = new Completer(); | 121 var completer = new Completer(); |
87 HttpServer.bind("127.0.0.1", 0).then((server) { | 122 HttpServer.bind("127.0.0.1", 0).then((server) { |
88 server.listen((request) { | 123 server.listen((request) { |
89 request.response.contentLength = 100; | 124 request.response.contentLength = 100; |
90 request.response.write("data"); | 125 request.response.write("data"); |
91 request.response.write("more data"); | 126 request.response.write("more data"); |
92 completer.future.then((_) => server.close()); | 127 completer.future.then((_) => server.close(force: true)); |
93 }); | 128 }); |
94 | 129 |
95 var client = new HttpClient(); | 130 var client = new HttpClient(); |
96 client.get("127.0.0.1", server.port, "/") | 131 client.get("127.0.0.1", server.port, "/") |
97 .then((request) => request.close()) | 132 .then((request) => request.close()) |
98 .then((response) { | 133 .then((response) { |
99 // Close the (incomplete) response, now that we have seen | 134 // Close the (incomplete) response, now that we have seen |
100 // the response object. | 135 // the response object. |
101 completer.complete(null); | 136 completer.complete(null); |
102 int errors = 0; | 137 int errors = 0; |
(...skipping 22 matching lines...) Expand all Loading... |
125 }); | 160 }); |
126 }); | 161 }); |
127 } | 162 } |
128 | 163 |
129 | 164 |
130 void main() { | 165 void main() { |
131 testGetEmptyRequest(); | 166 testGetEmptyRequest(); |
132 testGetDataRequest(); | 167 testGetDataRequest(); |
133 testGetInvalidHost(); | 168 testGetInvalidHost(); |
134 testGetServerClose(); | 169 testGetServerClose(); |
135 testGetDataServerClose(); | 170 testGetServerCloseNoKeepAlive(); |
| 171 testGetServerForceClose(); |
| 172 testGetDataServerForceClose(); |
136 testPostEmptyRequest(); | 173 testPostEmptyRequest(); |
137 } | 174 } |
OLD | NEW |