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

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

Issue 11411121: Generate an error for active connections when the HTTP client is shutdown (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed long line Created 8 years 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 5
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 void testNoBody(int totalConnections, bool explicitContentLength) { 9 void testNoBody(int totalConnections, bool explicitContentLength) {
10 HttpServer server = new HttpServer(); 10 HttpServer server = new HttpServer();
(...skipping 20 matching lines...) Expand all
31 request.contentLength = 0; 31 request.contentLength = 0;
32 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 32 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
33 } 33 }
34 stream.close(); 34 stream.close();
35 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 35 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
36 }; 36 };
37 conn.onResponse = (HttpClientResponse response) { 37 conn.onResponse = (HttpClientResponse response) {
38 Expect.equals("0", response.headers.value('content-length')); 38 Expect.equals("0", response.headers.value('content-length'));
39 Expect.equals(0, response.contentLength); 39 Expect.equals(0, response.contentLength);
40 count++; 40 count++;
41 if (count == totalConnections) { 41 response.inputStream.onData = response.inputStream.read;
42 client.shutdown(); 42 response.inputStream.onClosed = () {
43 server.close(); 43 if (count == totalConnections) {
44 } 44 client.shutdown();
45 server.close();
46 }
47 };
45 }; 48 };
46 } 49 }
47 } 50 }
48 51
49 void testBody(int totalConnections) { 52 void testBody(int totalConnections) {
50 HttpServer server = new HttpServer(); 53 HttpServer server = new HttpServer();
51 server.onError = (e) => Expect.fail("Unexpected error $e"); 54 server.onError = (e) => Expect.fail("Unexpected error $e");
52 server.listen("127.0.0.1", 0, backlog: totalConnections); 55 server.listen("127.0.0.1", 0, backlog: totalConnections);
53 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 56 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
54 Expect.equals("2", request.headers.value('content-length')); 57 Expect.equals("2", request.headers.value('content-length'));
(...skipping 20 matching lines...) Expand all
75 Expect.throws(() => request.contentLength = 3, (e) => e is HttpException); 78 Expect.throws(() => request.contentLength = 3, (e) => e is HttpException);
76 stream.writeString("x"); 79 stream.writeString("x");
77 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 80 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
78 stream.close(); 81 stream.close();
79 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); 82 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
80 }; 83 };
81 conn.onResponse = (HttpClientResponse response) { 84 conn.onResponse = (HttpClientResponse response) {
82 Expect.equals("2", response.headers.value('content-length')); 85 Expect.equals("2", response.headers.value('content-length'));
83 Expect.equals(2, response.contentLength); 86 Expect.equals(2, response.contentLength);
84 count++; 87 count++;
85 if (count == totalConnections) { 88 response.inputStream.onData = response.inputStream.read;
86 client.shutdown(); 89 response.inputStream.onClosed = () {
87 server.close(); 90 if (count == totalConnections) {
88 } 91 client.shutdown();
92 server.close();
93 }
94 };
89 }; 95 };
90 } 96 }
91 } 97 }
92 98
93 void testHttp10() { 99 void testHttp10() {
94 HttpServer server = new HttpServer(); 100 HttpServer server = new HttpServer();
95 server.onError = (e) => Expect.fail("Unexpected error $e"); 101 server.onError = (e) => Expect.fail("Unexpected error $e");
96 server.listen("127.0.0.1", 0, backlog: 5); 102 server.listen("127.0.0.1", 0, backlog: 5);
97 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 103 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
98 Expect.isNull(request.headers.value('content-length')); 104 Expect.isNull(request.headers.value('content-length'));
(...skipping 16 matching lines...) Expand all
115 }; 121 };
116 }; 122 };
117 } 123 }
118 124
119 void main() { 125 void main() {
120 testNoBody(5, false); 126 testNoBody(5, false);
121 testNoBody(5, true); 127 testNoBody(5, true);
122 testBody(5); 128 testBody(5);
123 testHttp10(); 129 testHttp10();
124 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698