| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.runner.loader; | 5 library test.runner.loader; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| 11 import 'package:analyzer/analyzer.dart'; | 11 import 'package:analyzer/analyzer.dart'; |
| 12 import 'package:async/async.dart'; |
| 12 import 'package:path/path.dart' as p; | 13 import 'package:path/path.dart' as p; |
| 13 import 'package:stack_trace/stack_trace.dart'; | 14 import 'package:stack_trace/stack_trace.dart'; |
| 14 | 15 |
| 15 import '../backend/invoker.dart'; | 16 import '../backend/invoker.dart'; |
| 16 import '../backend/metadata.dart'; | 17 import '../backend/metadata.dart'; |
| 17 import '../backend/test_platform.dart'; | 18 import '../backend/test_platform.dart'; |
| 18 import '../util/async_thunk.dart'; | |
| 19 import '../util/dart.dart' as dart; | 19 import '../util/dart.dart' as dart; |
| 20 import '../util/io.dart'; | 20 import '../util/io.dart'; |
| 21 import '../util/remote_exception.dart'; | 21 import '../util/remote_exception.dart'; |
| 22 import '../utils.dart'; | 22 import '../utils.dart'; |
| 23 import 'browser/server.dart'; | 23 import 'browser/server.dart'; |
| 24 import 'load_exception.dart'; | 24 import 'load_exception.dart'; |
| 25 import 'load_suite.dart'; | 25 import 'load_suite.dart'; |
| 26 import 'parse_metadata.dart'; | 26 import 'parse_metadata.dart'; |
| 27 import 'runner_suite.dart'; | 27 import 'runner_suite.dart'; |
| 28 import 'vm/isolate_test.dart'; | 28 import 'vm/isolate_test.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 /// This is `null` if tests should be loaded from the filesystem. | 53 /// This is `null` if tests should be loaded from the filesystem. |
| 54 final Uri _pubServeUrl; | 54 final Uri _pubServeUrl; |
| 55 | 55 |
| 56 /// All suites that have been created by the loader. | 56 /// All suites that have been created by the loader. |
| 57 final _suites = new Set<RunnerSuite>(); | 57 final _suites = new Set<RunnerSuite>(); |
| 58 | 58 |
| 59 /// The server that serves browser test pages. | 59 /// The server that serves browser test pages. |
| 60 /// | 60 /// |
| 61 /// This is lazily initialized the first time it's accessed. | 61 /// This is lazily initialized the first time it's accessed. |
| 62 Future<BrowserServer> get _browserServer { | 62 Future<BrowserServer> get _browserServer { |
| 63 return _browserServerThunk.run(() { | 63 return _browserServerMemo.runOnce(() { |
| 64 return BrowserServer.start( | 64 return BrowserServer.start( |
| 65 root: _root, | 65 root: _root, |
| 66 packageRoot: _packageRoot, | 66 packageRoot: _packageRoot, |
| 67 pubServeUrl: _pubServeUrl, | 67 pubServeUrl: _pubServeUrl, |
| 68 color: _color, | 68 color: _color, |
| 69 jsTrace: _jsTrace); | 69 jsTrace: _jsTrace); |
| 70 }); | 70 }); |
| 71 } | 71 } |
| 72 final _browserServerThunk = new AsyncThunk<BrowserServer>(); | 72 final _browserServerMemo = new AsyncMemoizer<BrowserServer>(); |
| 73 | 73 |
| 74 /// The thunk for running [close] exactly once. | 74 /// The memoizer for running [close] exactly once. |
| 75 final _closeThunk = new AsyncThunk(); | 75 final _closeMemo = new AsyncMemoizer(); |
| 76 | 76 |
| 77 /// Creates a new loader. | 77 /// Creates a new loader. |
| 78 /// | 78 /// |
| 79 /// [root] is the root directory that will be served for browser tests. It | 79 /// [root] is the root directory that will be served for browser tests. It |
| 80 /// defaults to the working directory. | 80 /// defaults to the working directory. |
| 81 /// | 81 /// |
| 82 /// If [packageRoot] is passed, it's used as the package root for all loaded | 82 /// If [packageRoot] is passed, it's used as the package root for all loaded |
| 83 /// tests. Otherwise, it's inferred from [root]. | 83 /// tests. Otherwise, it's inferred from [root]. |
| 84 /// | 84 /// |
| 85 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` | 85 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 onClose: isolate.kill); | 273 onClose: isolate.kill); |
| 274 _suites.add(suite); | 274 _suites.add(suite); |
| 275 return suite; | 275 return suite; |
| 276 } finally { | 276 } finally { |
| 277 subscription.cancel(); | 277 subscription.cancel(); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 /// Closes the loader and releases all resources allocated by it. | 281 /// Closes the loader and releases all resources allocated by it. |
| 282 Future close() { | 282 Future close() { |
| 283 return _closeThunk.run(() async { | 283 return _closeMemo.runOnce(() async { |
| 284 await Future.wait(_suites.map((suite) => suite.close())); | 284 await Future.wait(_suites.map((suite) => suite.close())); |
| 285 _suites.clear(); | 285 _suites.clear(); |
| 286 | 286 |
| 287 if (!_browserServerThunk.hasRun) return; | 287 if (!_browserServerMemo.hasRun) return; |
| 288 await (await _browserServer).close(); | 288 await (await _browserServer).close(); |
| 289 }); | 289 }); |
| 290 } | 290 } |
| 291 } | 291 } |
| OLD | NEW |