| OLD | NEW |
| 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 | 8 |
| 9 // NOTE: This test tries to ensure that an HttpClient will close it's | 9 // NOTE: This test tries to ensure that an HttpClient will close it's |
| 10 // underlying idle connections after [HttpClient.idleTimeout]. | 10 // underlying idle connections after [HttpClient.idleTimeout]. |
| 11 // | 11 // |
| 12 // The main script spawns a server and a subprocess which does a connection back | 12 // The main script spawns a server and a subprocess which does a connection back |
| 13 // to it. | 13 // to it. |
| 14 // The subprocess is expected to shut down it's idle sockets after | 14 // The subprocess is expected to shut down its idle sockets after |
| 15 // [HttpClient.idleTimeout] and the main script will assert that this happens | 15 // [HttpClient.idleTimeout] and the main script will assert that this happens |
| 16 // within +/- 2 <= seconds. | 16 // within +/- 2 <= seconds. |
| 17 | 17 |
| 18 const SECONDS = 4; | 18 const SECONDS = 4; |
| 19 | 19 |
| 20 List<String> packageOptions() { |
| 21 if (Platform.packageRoot != null) { |
| 22 return <String>['--package-root=${Platform.packageRoot}']; |
| 23 } else if (Platform.packageConfig != null) { |
| 24 return <String>['--packages=${Platform.packageConfig}']; |
| 25 } else { |
| 26 return <String>[]; |
| 27 } |
| 28 } |
| 29 |
| 20 void runServerProcess() { | 30 void runServerProcess() { |
| 21 asyncStart(); | 31 asyncStart(); |
| 22 HttpServer.bind('127.0.0.1', 0).then((server) { | 32 HttpServer.bind('127.0.0.1', 0).then((server) { |
| 23 var url = 'http://127.0.0.1:${server.port}/'; | 33 var url = 'http://127.0.0.1:${server.port}/'; |
| 24 | 34 |
| 25 server.idleTimeout = const Duration(hours: 1); | 35 server.idleTimeout = const Duration(hours: 1); |
| 26 | 36 |
| 27 var subscription = server.listen((HttpRequest request) { | 37 var subscription = server.listen((HttpRequest request) { |
| 28 return request.response..write('hello world')..close(); | 38 return request.response..write('hello world')..close(); |
| 29 }); | 39 }); |
| 30 | 40 |
| 31 var sw = new Stopwatch()..start(); | 41 var sw = new Stopwatch()..start(); |
| 32 var arguments = ['--package-root=${Platform.packageRoot}', | 42 var arguments = packageOptions()..add(Platform.script.toString())..add(url); |
| 33 '${Platform.script}', | |
| 34 url]; | |
| 35 Process.run(Platform.executable, arguments).then((res) { | 43 Process.run(Platform.executable, arguments).then((res) { |
| 36 subscription.cancel(); | 44 subscription.cancel(); |
| 37 if (res.exitCode != 0) { | 45 if (res.exitCode != 0) { |
| 38 throw "Child exited with ${res.exitCode} instead of 0. " | 46 throw "Child exited with ${res.exitCode} instead of 0. " |
| 39 "(stdout: ${res.stdout}, stderr: ${res.stderr})"; | 47 "(stdout: ${res.stdout}, stderr: ${res.stderr})"; |
| 40 } | 48 } |
| 41 var seconds = sw.elapsed.inSeconds; | 49 var seconds = sw.elapsed.inSeconds; |
| 42 // NOTE: There is a slight chance this will cause flakiness, but there is | 50 // NOTE: There is a slight chance this will cause flakiness, but there is |
| 43 // no other good way of testing correctness of timing-dependent code | 51 // no other good way of testing correctness of timing-dependent code |
| 44 // form the outside. | 52 // form the outside. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 .then((_) => print('drained client request')); | 74 .then((_) => print('drained client request')); |
| 67 } | 75 } |
| 68 | 76 |
| 69 void main(List<String> args) { | 77 void main(List<String> args) { |
| 70 if (args.length == 1) { | 78 if (args.length == 1) { |
| 71 runClientProcess(args.first); | 79 runClientProcess(args.first); |
| 72 } else { | 80 } else { |
| 73 runServerProcess(); | 81 runServerProcess(); |
| 74 } | 82 } |
| 75 } | 83 } |
| OLD | NEW |