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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 void testDeadlineAndDetach(int connections) { | 57 void testDeadlineAndDetach(int connections) { |
58 HttpServer.bind('localhost', 0).then((server) { | 58 HttpServer.bind('localhost', 0).then((server) { |
59 server.listen((request) { | 59 server.listen((request) { |
60 request.response.deadline = const Duration(milliseconds: 0); | 60 request.response.deadline = const Duration(milliseconds: 0); |
61 request.response.contentLength = 5; | 61 request.response.contentLength = 5; |
62 request.response.detachSocket().then((socket) { | 62 request.response.detachSocket().then((socket) { |
63 new Timer(const Duration(milliseconds: 100), () { | 63 new Timer(const Duration(milliseconds: 100), () { |
64 socket.write('stuff'); | 64 socket.write('stuff'); |
65 socket.close(); | 65 socket.close(); |
| 66 socket.listen(null); |
66 }); | 67 }); |
67 }); | 68 }); |
68 }); | 69 }); |
69 | 70 |
70 var futures = []; | 71 var futures = []; |
71 var client = new HttpClient(); | 72 var client = new HttpClient(); |
72 for (int i = 0; i < connections; i++) { | 73 for (int i = 0; i < connections; i++) { |
73 futures.add(client.get('localhost', server.port, '/') | 74 futures.add(client.get('localhost', server.port, '/') |
74 .then((request) => request.close()) | 75 .then((request) => request.close()) |
75 .then((response) { | 76 .then((response) { |
76 return response.fold(new BytesBuilder(), (b, d) => b..add(d)) | 77 return response.fold(new BytesBuilder(), (b, d) => b..add(d)) |
77 .then((builder) { | 78 .then((builder) { |
78 Expect.equals('stuff', | 79 Expect.equals('stuff', |
79 new String.fromCharCodes(builder.takeBytes())); | 80 new String.fromCharCodes(builder.takeBytes())); |
80 }); | 81 }); |
81 })); | 82 })); |
82 } | 83 } |
83 Future.wait(futures).then((_) => server.close()); | 84 Future.wait(futures).then((_) => server.close()); |
84 }); | 85 }); |
85 } | 86 } |
86 | 87 |
87 void main() { | 88 void main() { |
88 testSimpleDeadline(10); | 89 testSimpleDeadline(10); |
89 testExceedDeadline(10); | 90 testExceedDeadline(10); |
90 testDeadlineAndDetach(10); | 91 testDeadlineAndDetach(10); |
91 } | 92 } |
92 | 93 |
OLD | NEW |