| 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 24 matching lines...) Expand all Loading... |
| 35 // reports an error. | 35 // reports an error. |
| 36 response.write("x"); | 36 response.write("x"); |
| 37 // Subsequent write are ignored as there is already an | 37 // Subsequent write are ignored as there is already an |
| 38 // error. | 38 // error. |
| 39 response.write("x"); | 39 response.write("x"); |
| 40 // After an explicit close, write becomes a state error | 40 // After an explicit close, write becomes a state error |
| 41 // because we have said we will not add more. | 41 // because we have said we will not add more. |
| 42 response.close(); | 42 response.close(); |
| 43 response.write("x"); | 43 response.write("x"); |
| 44 }, | 44 }, |
| 45 onError: (e) { | 45 onError: (e, trace) { |
| 46 String msg = "Unexpected server error $e"; | 46 String msg = "Unexpected server error $e"; |
| 47 var trace = getAttachedStackTrace(e); | |
| 48 if (trace != null) msg += "\nStackTrace: $trace"; | 47 if (trace != null) msg += "\nStackTrace: $trace"; |
| 49 Expect.fail(msg); | 48 Expect.fail(msg); |
| 50 }); | 49 }); |
| 51 | 50 |
| 52 HttpClient client = new HttpClient(); | 51 HttpClient client = new HttpClient(); |
| 53 for (int i = 0; i < totalConnections; i++) { | 52 for (int i = 0; i < totalConnections; i++) { |
| 54 client.get("127.0.0.1", server.port, "/") | 53 client.get("127.0.0.1", server.port, "/") |
| 55 .then((request) { | 54 .then((request) { |
| 56 if (explicitContentLength) { | 55 if (explicitContentLength) { |
| 57 request.contentLength = 0; | 56 request.contentLength = 0; |
| 58 } | 57 } |
| 59 return request.close(); | 58 return request.close(); |
| 60 }) | 59 }) |
| 61 .then((response) { | 60 .then((response) { |
| 62 Expect.equals("0", response.headers.value('content-length')); | 61 Expect.equals("0", response.headers.value('content-length')); |
| 63 Expect.equals(0, response.contentLength); | 62 Expect.equals(0, response.contentLength); |
| 64 response.drain(); | 63 response.drain(); |
| 65 }) | 64 }) |
| 66 .catchError((e) { | 65 .catchError((e, trace) { |
| 67 String msg = "Unexpected error $e"; | 66 String msg = "Unexpected error $e"; |
| 68 var trace = getAttachedStackTrace(e); | |
| 69 if (trace != null) msg += "\nStackTrace: $trace"; | 67 if (trace != null) msg += "\nStackTrace: $trace"; |
| 70 Expect.fail(msg); | 68 Expect.fail(msg); |
| 71 }); | 69 }); |
| 72 } | 70 } |
| 73 }); | 71 }); |
| 74 } | 72 } |
| 75 | 73 |
| 76 void testBody(int totalConnections, bool useHeader) { | 74 void testBody(int totalConnections, bool useHeader) { |
| 77 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { | 75 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { |
| 78 int serverCount = 0; | 76 int serverCount = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 101 .catchError((error) { | 99 .catchError((error) { |
| 102 Expect.isTrue(error is HttpException, "[$error]"); | 100 Expect.isTrue(error is HttpException, "[$error]"); |
| 103 if (++serverCount == totalConnections) { | 101 if (++serverCount == totalConnections) { |
| 104 server.close(); | 102 server.close(); |
| 105 } | 103 } |
| 106 }); | 104 }); |
| 107 response.close(); | 105 response.close(); |
| 108 response.write("x"); | 106 response.write("x"); |
| 109 }); | 107 }); |
| 110 }, | 108 }, |
| 111 onError: (e) { | 109 onError: (e, trace) { |
| 112 String msg = "Unexpected error $e"; | 110 String msg = "Unexpected error $e"; |
| 113 var trace = getAttachedStackTrace(e); | |
| 114 if (trace != null) msg += "\nStackTrace: $trace"; | 111 if (trace != null) msg += "\nStackTrace: $trace"; |
| 115 Expect.fail(msg); | 112 Expect.fail(msg); |
| 116 }); | 113 }); |
| 117 | 114 |
| 118 int clientCount = 0; | 115 int clientCount = 0; |
| 119 HttpClient client = new HttpClient(); | 116 HttpClient client = new HttpClient(); |
| 120 for (int i = 0; i < totalConnections; i++) { | 117 for (int i = 0; i < totalConnections; i++) { |
| 121 client.get("127.0.0.1", server.port, "/") | 118 client.get("127.0.0.1", server.port, "/") |
| 122 .then((request) { | 119 .then((request) { |
| 123 if (useHeader) { | 120 if (useHeader) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 .then((response) { | 132 .then((response) { |
| 136 Expect.equals("2", response.headers.value('content-length')); | 133 Expect.equals("2", response.headers.value('content-length')); |
| 137 Expect.equals(2, response.contentLength); | 134 Expect.equals(2, response.contentLength); |
| 138 response.listen( | 135 response.listen( |
| 139 (d) {}, | 136 (d) {}, |
| 140 onDone: () { | 137 onDone: () { |
| 141 if (++clientCount == totalConnections) { | 138 if (++clientCount == totalConnections) { |
| 142 client.close(); | 139 client.close(); |
| 143 } | 140 } |
| 144 }, | 141 }, |
| 145 onError: (error) { | 142 onError: (error, trace) { |
| 146 // Undefined what server response sends. | 143 // Undefined what server response sends. |
| 147 }); | 144 }); |
| 148 }); | 145 }); |
| 149 } | 146 } |
| 150 }); | 147 }); |
| 151 } | 148 } |
| 152 | 149 |
| 153 void testBodyChunked(int totalConnections, bool useHeader) { | 150 void testBodyChunked(int totalConnections, bool useHeader) { |
| 154 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { | 151 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { |
| 155 server.listen( | 152 server.listen( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 response.write("x"); | 167 response.write("x"); |
| 171 Expect.throws( | 168 Expect.throws( |
| 172 () => response.headers.chunkedTransferEncoding = false, | 169 () => response.headers.chunkedTransferEncoding = false, |
| 173 (e) => e is HttpException); | 170 (e) => e is HttpException); |
| 174 response.write("x"); | 171 response.write("x"); |
| 175 response.write("x"); | 172 response.write("x"); |
| 176 response.close(); | 173 response.close(); |
| 177 response.write("x"); | 174 response.write("x"); |
| 178 }); | 175 }); |
| 179 }, | 176 }, |
| 180 onError: (e) { | 177 onError: (e, trace) { |
| 181 String msg = "Unexpected error $e"; | 178 String msg = "Unexpected error $e"; |
| 182 var trace = getAttachedStackTrace(e); | |
| 183 if (trace != null) msg += "\nStackTrace: $trace"; | 179 if (trace != null) msg += "\nStackTrace: $trace"; |
| 184 Expect.fail(msg); | 180 Expect.fail(msg); |
| 185 }); | 181 }); |
| 186 | 182 |
| 187 int count = 0; | 183 int count = 0; |
| 188 HttpClient client = new HttpClient(); | 184 HttpClient client = new HttpClient(); |
| 189 for (int i = 0; i < totalConnections; i++) { | 185 for (int i = 0; i < totalConnections; i++) { |
| 190 client.get("127.0.0.1", server.port, "/") | 186 client.get("127.0.0.1", server.port, "/") |
| 191 .then((request) { | 187 .then((request) { |
| 192 if (useHeader) { | 188 if (useHeader) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 208 Expect.equals(-1, response.contentLength); | 204 Expect.equals(-1, response.contentLength); |
| 209 response.listen( | 205 response.listen( |
| 210 (d) {}, | 206 (d) {}, |
| 211 onDone: () { | 207 onDone: () { |
| 212 if (++count == totalConnections) { | 208 if (++count == totalConnections) { |
| 213 client.close(); | 209 client.close(); |
| 214 server.close(); | 210 server.close(); |
| 215 } | 211 } |
| 216 }); | 212 }); |
| 217 }) | 213 }) |
| 218 .catchError((e) { | 214 .catchError((e, trace) { |
| 219 String msg = "Unexpected error $e"; | 215 String msg = "Unexpected error $e"; |
| 220 var trace = getAttachedStackTrace(e); | |
| 221 if (trace != null) msg += "\nStackTrace: $trace"; | 216 if (trace != null) msg += "\nStackTrace: $trace"; |
| 222 Expect.fail(msg); | 217 Expect.fail(msg); |
| 223 }); | 218 }); |
| 224 } | 219 } |
| 225 }); | 220 }); |
| 226 } | 221 } |
| 227 | 222 |
| 228 void testSetContentLength() { | 223 void testSetContentLength() { |
| 229 HttpServer.bind("127.0.0.1", 0).then((server) { | 224 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 230 server.listen( | 225 server.listen( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 257 testNoBody(5, false); | 252 testNoBody(5, false); |
| 258 testNoBody(25, false); | 253 testNoBody(25, false); |
| 259 testNoBody(5, true); | 254 testNoBody(5, true); |
| 260 testNoBody(25, true); | 255 testNoBody(25, true); |
| 261 testBody(5, false); | 256 testBody(5, false); |
| 262 testBody(5, true); | 257 testBody(5, true); |
| 263 testBodyChunked(5, false); | 258 testBodyChunked(5, false); |
| 264 testBodyChunked(5, true); | 259 testBodyChunked(5, true); |
| 265 testSetContentLength(); | 260 testSetContentLength(); |
| 266 } | 261 } |
| OLD | NEW |