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

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

Issue 12334117: Fix http_close_test to wait for server close. (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 // 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:async";
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 client.get("localhost", server.port, "/") 63 client.get("localhost", server.port, "/")
64 .then((request) => request.close()) 64 .then((request) => request.close())
65 .then((response) => check()); 65 .then((response) => check());
66 } 66 }
67 }); 67 });
68 } 68 }
69 69
70 70
71 void testClientCloseDelayed(int connections) { 71 void testClientCloseDelayed(int connections) {
72 HttpServer.bind().then((server) { 72 HttpServer.bind().then((server) {
73 int closed = 0;
74 void check() {
75 closed++;
76 // Wait for both server and client to see the connections as closed.
77 if (closed == connections * 2) {
78 Expect.equals(0, server.connectionsInfo().active);
79 Expect.equals(server.connectionsInfo().total,
80 server.connectionsInfo().idle);
81 server.close();
82 }
83 }
73 server.listen((request) { 84 server.listen((request) {
74 request.pipe(request.response); 85 request.pipe(request.response)
86 .then((_) => check());
75 }); 87 });
76 int closed = 0;
77 var client = new HttpClient(); 88 var client = new HttpClient();
78 for (int i = 0; i < connections; i++) { 89 for (int i = 0; i < connections; i++) {
79 var req; 90 var req;
80 client.post("localhost", server.port, "/") 91 client.post("localhost", server.port, "/")
81 .then((request) { 92 .then((request) {
82 req = request; 93 req = request;
83 request.add(new Uint8List(1024)); 94 request.add(new Uint8List(1024));
84 return request.response; 95 return request.response;
85 }) 96 })
86 .then((response) { 97 .then((response) {
87 req.close(); 98 req.close();
88 // Ensure we don't accept the response until we have send the entire 99 // Ensure we don't accept the response until we have send the entire
89 // request. 100 // request.
90 response.listen( 101 response.listen(
91 (_) {}, 102 (_) {},
92 onDone: () { 103 onDone: () {
93 closed++; 104 check();
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 }); 105 });
101 }); 106 });
102 } 107 }
103 }); 108 });
104 } 109 }
105 110
106 111
107 void main() { 112 void main() {
108 testClientAndServerCloseNoListen(10); 113 testClientAndServerCloseNoListen(10);
109 testClientCloseServerListen(10); 114 testClientCloseServerListen(10);
110 testClientCloseDelayed(10); 115 testClientCloseDelayed(10);
111 } 116 }
112 117
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