Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: tests/standalone/io/http_content_length_test.dart

Issue 16375005: Fix http_content_length_test by not closing the server from the client. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 //
5 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
4 9
5 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
6 import "dart:async"; 11 import "dart:async";
7 import "dart:isolate"; 12 import "dart:isolate";
8 import "dart:io"; 13 import "dart:io";
9 14
10 void testNoBody(int totalConnections, bool explicitContentLength) { 15 void testNoBody(int totalConnections, bool explicitContentLength) {
11 var errors = 0; 16 int count = 0;
12 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) { 17 HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) {
13 server.listen( 18 server.listen(
14 (HttpRequest request) { 19 (HttpRequest request) {
15 Expect.equals("0", request.headers.value('content-length')); 20 Expect.equals("0", request.headers.value('content-length'));
16 Expect.equals(0, request.contentLength); 21 Expect.equals(0, request.contentLength);
17 var response = request.response; 22 var response = request.response;
18 response.contentLength = 0; 23 response.contentLength = 0;
19 response.done 24 response.done
20 .then((_) { 25 .then((_) {
21 Expect.fail("Unexpected successful response completion"); 26 Expect.fail("Unexpected successful response completion");
22 }) 27 })
23 .catchError((error) { 28 .catchError((error) {
24 Expect.isTrue(error is HttpException); 29 Expect.isTrue(error is HttpException);
30 if (++count == totalConnections) {
31 server.close();
32 }
25 }); 33 });
26 // write with content length 0 closes the connection and 34 // write with content length 0 closes the connection and
27 // reports an error. 35 // reports an error.
28 response.write("x"); 36 response.write("x");
29 // Subsequent write are ignored as there is already an 37 // Subsequent write are ignored as there is already an
30 // error. 38 // error.
31 response.write("x"); 39 response.write("x");
32 // After an explicit close, write becomes a state error 40 // After an explicit close, write becomes a state error
33 // because we have said we will not add more. 41 // because we have said we will not add more.
34 response.close(); 42 response.close();
35 Expect.throws(() => response.write("x"), 43 Expect.throws(() => response.write("x"),
36 (e) => e is StateError); 44 (e) => e is StateError);
37 }, 45 },
38 onError: (e) { 46 onError: (e) {
39 String msg = "Unexpected server error $e"; 47 String msg = "Unexpected server error $e";
40 var trace = getAttachedStackTrace(e); 48 var trace = getAttachedStackTrace(e);
41 if (trace != null) msg += "\nStackTrace: $trace"; 49 if (trace != null) msg += "\nStackTrace: $trace";
42 Expect.fail(msg); 50 Expect.fail(msg);
43 }); 51 });
44 52
45 int count = 0;
46 HttpClient client = new HttpClient(); 53 HttpClient client = new HttpClient();
47 for (int i = 0; i < totalConnections; i++) { 54 for (int i = 0; i < totalConnections; i++) {
48 client.get("127.0.0.1", server.port, "/") 55 client.get("127.0.0.1", server.port, "/")
49 .then((request) { 56 .then((request) {
50 if (explicitContentLength) { 57 if (explicitContentLength) {
51 request.contentLength = 0; 58 request.contentLength = 0;
52 } 59 }
53 return request.close(); 60 return request.close();
54 }) 61 })
55 .then((response) { 62 .then((response) {
56 Expect.equals("0", response.headers.value('content-length')); 63 Expect.equals("0", response.headers.value('content-length'));
57 Expect.equals(0, response.contentLength); 64 Expect.equals(0, response.contentLength);
58 response.listen( 65 response.drain();
59 (d) {},
60 onDone: () {
61 if (++count == totalConnections) {
62 client.close();
63 server.close();
64 }
65 });
66 }) 66 })
67 .catchError((e) { 67 .catchError((e) {
68 String msg = "Unexpected error $e"; 68 String msg = "Unexpected error $e";
69 var trace = getAttachedStackTrace(e); 69 var trace = getAttachedStackTrace(e);
70 if (trace != null) msg += "\nStackTrace: $trace"; 70 if (trace != null) msg += "\nStackTrace: $trace";
71 Expect.fail(msg); 71 Expect.fail(msg);
72 }); 72 });
73 } 73 }
74 }); 74 });
75 } 75 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 onDone: () { 251 onDone: () {
252 client.close(); 252 client.close();
253 server.close(); 253 server.close();
254 }); 254 });
255 }); 255 });
256 }); 256 });
257 } 257 }
258 258
259 void main() { 259 void main() {
260 testNoBody(5, false); 260 testNoBody(5, false);
261 testNoBody(25, false);
261 testNoBody(5, true); 262 testNoBody(5, true);
263 testNoBody(25, true);
262 testBody(5, false); 264 testBody(5, false);
263 testBody(5, true); 265 testBody(5, true);
264 testBodyChunked(5, false); 266 testBodyChunked(5, false);
265 testBodyChunked(5, true); 267 testBodyChunked(5, true);
266 testSetContentLength(); 268 testSetContentLength();
267 } 269 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698