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

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

Issue 12385041: Don't close the server until we have received the error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | no next file » | 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 4
5 import "dart:isolate"; 5 import "dart:isolate";
6 import "dart:io"; 6 import "dart:io";
7 7
8 void testNoBody(int totalConnections, bool explicitContentLength) { 8 void testNoBody(int totalConnections, bool explicitContentLength) {
9 var errors = 0; 9 var errors = 0;
10 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { 10 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 }) 61 })
62 .catchError((e) { 62 .catchError((e) {
63 Expect.fail("Unexpected error $e"); 63 Expect.fail("Unexpected error $e");
64 }); 64 });
65 } 65 }
66 }); 66 });
67 } 67 }
68 68
69 void testBody(int totalConnections, bool useHeader) { 69 void testBody(int totalConnections, bool useHeader) {
70 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { 70 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) {
71 int serverCount = 0;
71 server.listen( 72 server.listen(
72 (HttpRequest request) { 73 (HttpRequest request) {
73 Expect.equals("2", request.headers.value('content-length')); 74 Expect.equals("2", request.headers.value('content-length'));
74 Expect.equals(2, request.contentLength); 75 Expect.equals(2, request.contentLength);
75 var response = request.response; 76 var response = request.response;
76 if (useHeader) { 77 if (useHeader) {
77 response.contentLength = 2; 78 response.contentLength = 2;
78 } else { 79 } else {
79 response.headers.set("content-length", 2); 80 response.headers.set("content-length", 2);
80 } 81 }
81 request.listen( 82 request.listen(
82 (d) {}, 83 (d) {},
83 onDone: () { 84 onDone: () {
84 response.addString("x"); 85 response.addString("x");
85 Expect.throws(() => response.contentLength = 3, 86 Expect.throws(() => response.contentLength = 3,
86 (e) => e is HttpException); 87 (e) => e is HttpException);
87 response.addString("x"); 88 response.addString("x");
88 response.addString("x"); 89 response.addString("x");
89 response.done 90 response.done
90 .then((_) { 91 .then((_) {
91 Expect.fail("Unexpected successful response completion"); 92 Expect.fail("Unexpected successful response completion");
92 }) 93 })
93 .catchError((e) { 94 .catchError((e) {
94 Expect.isTrue(e.error is HttpException, "[$e] [${e.error}] "); 95 Expect.isTrue(e.error is HttpException, "[$e]");
96 if (++serverCount == totalConnections) {
97 server.close();
98 }
95 }); 99 });
96 response.close(); 100 response.close();
97 Expect.throws(() => response.addString("x"), 101 Expect.throws(() => response.addString("x"),
98 (e) => e is StateError); 102 (e) => e is StateError);
99 }); 103 });
100 }, 104 },
101 onError: (e) => Expect.fail("Unexpected error $e")); 105 onError: (e) => Expect.fail("Unexpected error $e"));
102 106
103 int count = 0; 107 int clientCount = 0;
104 HttpClient client = new HttpClient(); 108 HttpClient client = new HttpClient();
105 for (int i = 0; i < totalConnections; i++) { 109 for (int i = 0; i < totalConnections; i++) {
106 client.get("127.0.0.1", server.port, "/") 110 client.get("127.0.0.1", server.port, "/")
107 .then((request) { 111 .then((request) {
108 if (useHeader) { 112 if (useHeader) {
109 request.contentLength = 2; 113 request.contentLength = 2;
110 } else { 114 } else {
111 request.headers.add(HttpHeaders.CONTENT_LENGTH, "7"); 115 request.headers.add(HttpHeaders.CONTENT_LENGTH, "7");
112 request.headers.add(HttpHeaders.CONTENT_LENGTH, "2"); 116 request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
113 } 117 }
114 request.addString("x"); 118 request.addString("x");
115 Expect.throws(() => request.contentLength = 3, 119 Expect.throws(() => request.contentLength = 3,
116 (e) => e is HttpException); 120 (e) => e is HttpException);
117 request.addString("x"); 121 request.addString("x");
118 return request.close(); 122 return request.close();
119 }) 123 })
120 .then((response) { 124 .then((response) {
121 Expect.equals("2", response.headers.value('content-length')); 125 Expect.equals("2", response.headers.value('content-length'));
122 Expect.equals(2, response.contentLength); 126 Expect.equals(2, response.contentLength);
123 response.listen( 127 response.listen(
124 (d) {}, 128 (d) {},
125 onDone: () { 129 onDone: () {
126 if (++count == totalConnections) { 130 if (++clientCount == totalConnections) {
127 client.close(); 131 client.close();
128 server.close();
129 } 132 }
130 }); 133 });
131 }); 134 });
132 } 135 }
133 }); 136 });
134 } 137 }
135 138
136 void testBodyChunked(int totalConnections, bool useHeader) { 139 void testBodyChunked(int totalConnections, bool useHeader) {
137 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) { 140 HttpServer.bind("127.0.0.1", 0, totalConnections).then((server) {
138 server.listen( 141 server.listen(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 236
234 void main() { 237 void main() {
235 testNoBody(5, false); 238 testNoBody(5, false);
236 testNoBody(5, true); 239 testNoBody(5, true);
237 testBody(5, false); 240 testBody(5, false);
238 testBody(5, true); 241 testBody(5, true);
239 testBodyChunked(5, false); 242 testBodyChunked(5, false);
240 testBodyChunked(5, true); 243 testBodyChunked(5, true);
241 testHttp10(); 244 testHttp10();
242 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698