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

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

Issue 486853005: Fix idle connection pool issue in dart:io's HttpClient (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | « dart/sdk/lib/io/http_impl.dart ('k') | 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
(Empty)
1 import 'dart:io';
2
3 const SECONDS = 10;
4
5 void runServerProcess() {
6 HttpServer.bind('127.0.0.1', 0).then((server) {
7 var url = 'http://127.0.0.1:${server.port}/';
8
9 server.idleTimeout = const Duration(hours: 1);
10
11 var subscription = server.listen((HttpRequest request) {
12 return request.response..write('hello world')..close();
13 });
14
15 var sw = new Stopwatch()..start();
16 Process.run(Platform.executable, ['${Platform.script}', url]).then((res) {
17 subscription.cancel();
18 if (res.exitCode != 0) {
19 throw "Child exited with ${res.exitCode} instead of 0";
20 }
21 var seconds = sw.elapsed.inSeconds;
22 if ((SECONDS - seconds).abs() > 2) {
Søren Gjesse 2014/08/26 06:56:05 Of cause this has flake potential... but maybe 2 s
kustermann 2014/08/26 09:37:27 For the DartVM 2 seconds is a huge time. In fact
23 throw "Child did exit within $seconds seconds, but expected it to take "
24 "roughly $SECONDS seconds.";
25 }
26 });
27 });
28 }
29
30 void runClientProcess(String url) {
31 var uri = Uri.parse(url);
32
33 // NOTE: We make an HTTP client request and then *forget to close* the HTTP
34 // client instance. The idle timer should fire after SECONDS.
35 var client = new HttpClient();
36 client.idleTimeout = const Duration(seconds: SECONDS);
37
38 client.getUrl(uri)
39 .then((req) =>req.close())
40 .then((response) => response.drain())
41 .then((_) => print('drained client request'));
42 }
43
44 void main(List<String> args) {
45 if (args.length == 1) {
46 runClientProcess(args.first);
47 } else {
48 runServerProcess();
49 }
50 }
OLDNEW
« no previous file with comments | « dart/sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698