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

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

Issue 12317147: Implement addStream for HttpClientRequest/HttpResponse and propegate all write-errors from the sock… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extend test. 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
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 // 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:io"; 11 import "dart:io";
11 import "dart:scalarlist"; 12 import "dart:scalarlist";
12 13
13 void testServerRequest(void handler(server, request)) { 14 void testServerRequest(void handler(server, request), {int bytes}) {
14 HttpServer.bind().then((server) { 15 HttpServer.bind().then((server) {
15 server.listen((request) { 16 server.listen((request) {
16 handler(server, request); 17 handler(server, request);
17 }); 18 });
18 19
19 var client = new HttpClient(); 20 var client = new HttpClient();
20 // We only close the client on either 21 // We only close the client on either
21 // - Bad response headers 22 // - Bad response headers
22 // - Response done (with optional errors in between). 23 // - Response done (with optional errors in between).
23 client.get("127.0.0.1", server.port, "/") 24 client.get("127.0.0.1", server.port, "/")
24 .then((request) => request.close()) 25 .then((request) => request.close())
25 .then((response) { 26 .then((response) {
26 response.listen((_) {}, onDone: () { 27 int received = 0;
27 client.close(); 28 response.listen(
28 }, onError: (error) { 29 (data) => received += data.length,
29 Expect.isTrue(error.error is HttpParserException); 30 onDone: () {
30 }); 31 if (bytes != null) Expect.equals(received, bytes);
32 client.close();
33 },
34 onError: (error) {
35 Expect.isTrue(error.error is HttpParserException);
36 });
31 }) 37 })
32 .catchError((error) { 38 .catchError((error) {
33 client.close(); 39 client.close();
34 }, test: (e) => e is HttpParserException); 40 }, test: (e) => e is HttpParserException);
35 }); 41 });
36 } 42 }
37 43
38 void testResponseDone() { 44 void testResponseDone() {
39 testServerRequest((server, request) { 45 testServerRequest((server, request) {
40 request.response.close(); 46 request.response.close();
41 request.response.done.then((response) { 47 request.response.done.then((response) {
42 Expect.equals(request.response, response); 48 Expect.equals(request.response, response);
43 server.close(); 49 server.close();
44 }); 50 });
45 }); 51 });
46 } 52 }
47 53
54 void testResponseAddStream() {
55 int bytes = new File(new Options().script).lengthSync();
56
57 testServerRequest((server, request) {
58 request.response.addStream(new File(new Options().script).openRead())
59 .then((response) {
60 response.close();
61 response.done.then((_) => server.close());
62 });
63 }, bytes: bytes);
64
65 testServerRequest((server, request) {
66 request.response.addStream(new File(new Options().script).openRead())
67 .then((response) {
68 request.response.addStream(new File(new Options().script).openRead())
69 .then((response) {
70 response.close();
71 response.done.then((_) => server.close());
72 });
73 });
74 }, bytes: bytes * 2);
75
76 testServerRequest((server, request) {
77 var controller = new StreamController();
78 request.response.addStream(controller.stream)
79 .then((response) {
80 response.close();
81 response.done.then((_) => server.close());
82 });
83 controller.close();
84 }, bytes: 0);
85 }
86
48 void testBadResponseAdd() { 87 void testBadResponseAdd() {
49 testServerRequest((server, request) { 88 testServerRequest((server, request) {
50 request.response.contentLength = 0; 89 request.response.contentLength = 0;
51 request.response.add([0]); 90 request.response.add([0]);
52 request.response.done.catchError((error) { 91 request.response.done.catchError((error) {
53 server.close(); 92 server.close();
54 }, test: (e) => e is HttpException); 93 }, test: (e) => e is HttpException);
55 }); 94 });
56 95
57 testServerRequest((server, request) { 96 testServerRequest((server, request) {
(...skipping 30 matching lines...) Expand all
88 request.response.add([0]); 127 request.response.add([0]);
89 request.response.close(); 128 request.response.close();
90 request.response.done.catchError((error) { 129 request.response.done.catchError((error) {
91 server.close(); 130 server.close();
92 }, test: (e) => e is HttpException); 131 }, test: (e) => e is HttpException);
93 }); 132 });
94 } 133 }
95 134
96 void main() { 135 void main() {
97 testResponseDone(); 136 testResponseDone();
137 testResponseAddStream();
98 testBadResponseAdd(); 138 testBadResponseAdd();
99 testBadResponseClose(); 139 testBadResponseClose();
100 } 140 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_request_pipeling_test.dart ('k') | tests/standalone/io/http_shutdown_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698