OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library http_server; | 5 library http_server; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'test_suite.dart'; // For TestUtils. | 9 import 'test_suite.dart'; // For TestUtils. |
| 10 // TODO(efortuna): Rewrite to not use the args library and simply take an |
| 11 // expected number of arguments, so test.dart doesn't rely on the args library? |
| 12 // See discussion on https://codereview.chromium.org/11931025/. |
| 13 import 'vendored_pkg/args/args.dart'; |
10 | 14 |
| 15 main() { |
| 16 /** Convenience method for local testing. */ |
| 17 var parser = new ArgParser(); |
| 18 parser.addOption('port', abbr: 'p', |
| 19 help: 'The main server port we wish to respond to requests.', |
| 20 defaultsTo: '0'); |
| 21 parser.addOption('crossOriginPort', abbr: 'c', |
| 22 help: 'A different port that accepts request from the main server port.', |
| 23 defaultsTo: '0'); |
| 24 parser.addOption('mode', abbr: 'm', help: 'Testing mode.', |
| 25 defaultsTo: 'release'); |
| 26 parser.addOption('arch', abbr: 'a', help: 'Testing architecture.', |
| 27 defaultsTo: 'ia32'); |
| 28 parser.addFlag('help', abbr: 'h', negatable: false, |
| 29 help: 'Print this usage information.'); |
| 30 var args = parser.parse(new Options().arguments); |
| 31 if (args['help']) { |
| 32 print(parser.getUsage()); |
| 33 } else { |
| 34 // Pretend we're running test.dart so that TestUtils doesn't get confused |
| 35 // about the "current directory." This is only used if we're trying to run |
| 36 // this file independently for local testing. |
| 37 TestUtils.testScriptPath = new Path(new Options().script) |
| 38 .directoryPath |
| 39 .join(new Path('../../test.dart')) |
| 40 .canonicalize() |
| 41 .toNativePath(); |
| 42 TestingServerRunner.setPackageRootDir({'mode': args['mode'], |
| 43 'arch': args['arch'], 'system': Platform.operatingSystem, |
| 44 'build_directory': ''}); |
| 45 |
| 46 TestingServerRunner.startHttpServer('127.0.0.1', |
| 47 port: int.parse(args['port'])); |
| 48 print('Server listening on port ' |
| 49 '${TestingServerRunner.serverList[0].port}.'); |
| 50 TestingServerRunner.startHttpServer('127.0.0.1', |
| 51 allowedPort: TestingServerRunner.serverList[0].port, port: |
| 52 int.parse(args['crossOriginPort'])); |
| 53 print( |
| 54 'Server listening on port ${TestingServerRunner.serverList[1].port}.'); |
| 55 } |
| 56 } |
11 /** | 57 /** |
12 * Runs a set of servers that are initialized specifically for the needs of our | 58 * Runs a set of servers that are initialized specifically for the needs of our |
13 * test framework, such as dealing with package-root. | 59 * test framework, such as dealing with package-root. |
14 */ | 60 */ |
15 class TestingServerRunner { | 61 class TestingServerRunner { |
16 static List serverList = []; | 62 static List serverList = []; |
17 static Path _packageRootDir = null; | 63 static Path _packageRootDir = null; |
18 | 64 |
19 // Added as a getter so that the function will be called again each time the | 65 // Added as a getter so that the function will be called again each time the |
20 // default request handler closure is executed. | 66 // default request handler closure is executed. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }); | 136 }); |
91 | 137 |
92 httpServer.listen(host, port); | 138 httpServer.listen(host, port); |
93 serverList.add(httpServer); | 139 serverList.add(httpServer); |
94 } | 140 } |
95 | 141 |
96 static terminateHttpServers() { | 142 static terminateHttpServers() { |
97 for (var server in serverList) server.close(); | 143 for (var server in serverList) server.close(); |
98 } | 144 } |
99 } | 145 } |
OLD | NEW |