Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |