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

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

Issue 12328114: Rewrite the Future-pipeline from the Socket to the HttpClientRequest/HttpResponse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing test file. 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 | « sdk/lib/io/io_stream_consumer.dart ('k') | tests/standalone/io/http_shutdown_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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
9
10 import "dart:async";
11 import "dart:io";
12 import "dart:scalarlist";
13
14
15 void testClientAndServerCloseNoListen(int connections) {
16 HttpServer.bind().then((server) {
17 int closed = 0;
18 server.listen((request) {
19 request.response.close();
20 request.response.done.then((_) {
21 closed++;
22 if (closed == connections) {
23 Expect.equals(0, server.connectionsInfo().active);
24 Expect.equals(server.connectionsInfo().total,
25 server.connectionsInfo().idle);
26 server.close();
27 }
28 });
29 });
30 var client = new HttpClient();
31 for (int i = 0; i < connections; i++) {
32 client.get("localhost", server.port, "/")
33 .then((request) => request.close())
34 .then((response) {
35 });
36 }
37 });
38 }
39
40
41 void testClientCloseServerListen(int connections) {
42 HttpServer.bind().then((server) {
43 int closed = 0;
44 void check() {
45 closed++;
46 if (closed == connections * 2) {
47 Expect.equals(0, server.connectionsInfo().active);
48 Expect.equals(server.connectionsInfo().total,
49 server.connectionsInfo().idle);
50 server.close();
51 }
52 }
53 server.listen((request) {
54 request.listen(
55 (_) {},
56 onDone: () {
57 request.response.close();
58 request.response.done.then((_) => check());
59 });
60 });
61 var client = new HttpClient();
62 for (int i = 0; i < connections; i++) {
63 client.get("localhost", server.port, "/")
64 .then((request) => request.close())
65 .then((response) => check());
66 }
67 });
68 }
69
70
71 void testClientCloseDelayed(int connections) {
72 HttpServer.bind().then((server) {
73 server.listen((request) {
74 request.pipe(request.response);
75 });
76 int closed = 0;
77 var client = new HttpClient();
78 for (int i = 0; i < connections; i++) {
79 var req;
80 client.post("localhost", server.port, "/")
81 .then((request) {
82 req = request;
83 request.add(new Uint8List(1024));
84 return request.response;
85 })
86 .then((response) {
87 req.close();
88 // Ensure we don't accept the response until we have send the entire
89 // request.
90 response.listen(
91 (_) {},
92 onDone: () {
93 closed++;
94 if (closed == connections) {
95 Expect.equals(0, server.connectionsInfo().active);
96 Expect.equals(server.connectionsInfo().total,
97 server.connectionsInfo().idle);
98 server.close();
99 }
100 });
101 });
102 }
103 });
104 }
105
106
107 void main() {
108 testClientAndServerCloseNoListen(10);
109 testClientCloseServerListen(10);
110 testClientCloseDelayed(10);
111 }
112
OLDNEW
« no previous file with comments | « sdk/lib/io/io_stream_consumer.dart ('k') | tests/standalone/io/http_shutdown_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698