Chromium Code Reviews| 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(); |
| + } |
| +} |