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 22 matching lines...) Expand all Loading... |
33 }); | 33 }); |
34 } | 34 } |
35 }); | 35 }); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 void test2(int totalConnections, int outputStreamWrites) { | 39 void test2(int totalConnections, int outputStreamWrites) { |
40 // Server which responds without waiting for request body. | 40 // Server which responds without waiting for request body. |
41 HttpServer.bind().then((server) { | 41 HttpServer.bind().then((server) { |
42 server.listen((HttpRequest request) { | 42 server.listen((HttpRequest request) { |
43 request.response.addString("!dlrow ,olleH"); | 43 request.response.write("!dlrow ,olleH"); |
44 request.response.close(); | 44 request.response.close(); |
45 }); | 45 }); |
46 | 46 |
47 int count = 0; | 47 int count = 0; |
48 HttpClient client = new HttpClient(); | 48 HttpClient client = new HttpClient(); |
49 for (int i = 0; i < totalConnections; i++) { | 49 for (int i = 0; i < totalConnections; i++) { |
50 client.get("127.0.0.1", server.port, "/") | 50 client.get("127.0.0.1", server.port, "/") |
51 .then((HttpClientRequest request) { | 51 .then((HttpClientRequest request) { |
52 request.contentLength = -1; | 52 request.contentLength = -1; |
53 for (int i = 0; i < outputStreamWrites; i++) { | 53 for (int i = 0; i < outputStreamWrites; i++) { |
54 request.addString("Hello, world!"); | 54 request.write("Hello, world!"); |
55 } | 55 } |
56 request.done.catchError((_) {}); | 56 request.done.catchError((_) {}); |
57 return request.close(); | 57 return request.close(); |
58 }) | 58 }) |
59 .then((HttpClientResponse response) { | 59 .then((HttpClientResponse response) { |
60 response.listen( | 60 response.listen( |
61 (_) {}, | 61 (_) {}, |
62 onDone: () { | 62 onDone: () { |
63 count++; | 63 count++; |
64 if (count == totalConnections) { | 64 if (count == totalConnections) { |
(...skipping 14 matching lines...) Expand all Loading... |
79 }); | 79 }); |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 void test3(int totalConnections) { | 83 void test3(int totalConnections) { |
84 // Server which responds when request body has been received. | 84 // Server which responds when request body has been received. |
85 HttpServer.bind().then((server) { | 85 HttpServer.bind().then((server) { |
86 | 86 |
87 server.listen((HttpRequest request) { | 87 server.listen((HttpRequest request) { |
88 request.listen((_) {}, onDone: () { | 88 request.listen((_) {}, onDone: () { |
89 request.response.addString("!dlrow ,olleH"); | 89 request.response.write("!dlrow ,olleH"); |
90 request.response.close(); | 90 request.response.close(); |
91 }); | 91 }); |
92 }); | 92 }); |
93 | 93 |
94 int count = 0; | 94 int count = 0; |
95 HttpClient client = new HttpClient(); | 95 HttpClient client = new HttpClient(); |
96 for (int i = 0; i < totalConnections; i++) { | 96 for (int i = 0; i < totalConnections; i++) { |
97 client.get("127.0.0.1", server.port, "/") | 97 client.get("127.0.0.1", server.port, "/") |
98 .then((HttpClientRequest request) { | 98 .then((HttpClientRequest request) { |
99 request.contentLength = -1; | 99 request.contentLength = -1; |
100 request.addString("Hello, world!"); | 100 request.write("Hello, world!"); |
101 return request.close(); | 101 return request.close(); |
102 }) | 102 }) |
103 .then((HttpClientResponse response) { | 103 .then((HttpClientResponse response) { |
104 response.listen((_) {}, onDone: () { | 104 response.listen((_) {}, onDone: () { |
105 count++; | 105 count++; |
106 if (count == totalConnections) { | 106 if (count == totalConnections) { |
107 client.close(); | 107 client.close(); |
108 server.close(); | 108 server.close(); |
109 } | 109 } |
110 }); | 110 }); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 }, | 157 }, |
158 onError: (error) { }); | 158 onError: (error) { }); |
159 | 159 |
160 // Create a number of client requests and keep then active. Then | 160 // Create a number of client requests and keep then active. Then |
161 // close the client and wait for the server to lose all active | 161 // close the client and wait for the server to lose all active |
162 // connections. | 162 // connections. |
163 var client= new HttpClient(); | 163 var client= new HttpClient(); |
164 for (int i = 0; i < totalConnections; i++) { | 164 for (int i = 0; i < totalConnections; i++) { |
165 client.post("127.0.0.1", server.port, "/") | 165 client.post("127.0.0.1", server.port, "/") |
166 .then((request) { | 166 .then((request) { |
167 request.add([0]); | 167 request.writeBytes([0]); |
168 // TODO(sgjesse): Make this test work with | 168 // TODO(sgjesse): Make this test work with |
169 //request.response instead of request.close() return | 169 //request.response instead of request.close() return |
170 //return request.response; | 170 //return request.response; |
171 request.done.catchError((e) {}); | 171 request.done.catchError((e) {}); |
172 return request.close(); | 172 return request.close(); |
173 }) | 173 }) |
174 .then((response) { }) | 174 .then((response) { }) |
175 .catchError((e) { }, test: (e) => e is HttpParserException); | 175 .catchError((e) { }, test: (e) => e is HttpParserException); |
176 } | 176 } |
177 bool clientClosed = false; | 177 bool clientClosed = false; |
(...skipping 19 matching lines...) Expand all Loading... |
197 test1(10); | 197 test1(10); |
198 test2(1, 10); | 198 test2(1, 10); |
199 test2(10, 10); | 199 test2(10, 10); |
200 test2(10, 1000); | 200 test2(10, 1000); |
201 test3(1); | 201 test3(1); |
202 test3(10); | 202 test3(10); |
203 test4(); | 203 test4(); |
204 test5(1); | 204 test5(1); |
205 test5(10); | 205 test5(10); |
206 } | 206 } |
OLD | NEW |