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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tests/standalone/io/http_client_stays_alive_test.dart
diff --git a/dart/tests/standalone/io/http_client_stays_alive_test.dart b/dart/tests/standalone/io/http_client_stays_alive_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3fe2e6e8a77b7b6570d4b476d68e59c505ea4f08
--- /dev/null
+++ b/dart/tests/standalone/io/http_client_stays_alive_test.dart
@@ -0,0 +1,50 @@
+import 'dart:io';
+
+const SECONDS = 10;
+
+void runServerProcess() {
+ HttpServer.bind('127.0.0.1', 0).then((server) {
+ var url = 'http://127.0.0.1:${server.port}/';
+
+ server.idleTimeout = const Duration(hours: 1);
+
+ var subscription = server.listen((HttpRequest request) {
+ return request.response..write('hello world')..close();
+ });
+
+ var sw = new Stopwatch()..start();
+ Process.run(Platform.executable, ['${Platform.script}', url]).then((res) {
+ subscription.cancel();
+ if (res.exitCode != 0) {
+ throw "Child exited with ${res.exitCode} instead of 0";
+ }
+ var seconds = sw.elapsed.inSeconds;
+ 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
+ throw "Child did exit within $seconds seconds, but expected it to take "
+ "roughly $SECONDS seconds.";
+ }
+ });
+ });
+}
+
+void runClientProcess(String url) {
+ var uri = Uri.parse(url);
+
+ // NOTE: We make an HTTP client request and then *forget to close* the HTTP
+ // client instance. The idle timer should fire after SECONDS.
+ var client = new HttpClient();
+ client.idleTimeout = const Duration(seconds: SECONDS);
+
+ client.getUrl(uri)
+ .then((req) =>req.close())
+ .then((response) => response.drain())
+ .then((_) => print('drained client request'));
+}
+
+void main(List<String> args) {
+ if (args.length == 1) {
+ runClientProcess(args.first);
+ } else {
+ runServerProcess();
+ }
+}
« 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