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.engine; | 5 library test.runner.engine; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:async/async.dart' hide Result; | 10 import 'package:async/async.dart' hide Result; |
11 import 'package:collection/collection.dart'; | 11 import 'package:collection/collection.dart'; |
12 import 'package:pool/pool.dart'; | 12 import 'package:pool/pool.dart'; |
13 | 13 |
14 import '../backend/live_test.dart'; | 14 import '../backend/live_test.dart'; |
15 import '../backend/live_test_controller.dart'; | 15 import '../backend/live_test_controller.dart'; |
16 import '../backend/state.dart'; | 16 import '../backend/state.dart'; |
17 import '../backend/suite.dart'; | 17 import '../backend/suite.dart'; |
18 import '../backend/test.dart'; | 18 import '../backend/test.dart'; |
19 import '../util/delegating_sink.dart'; | |
20 import 'load_suite.dart'; | 19 import 'load_suite.dart'; |
21 | 20 |
22 /// An [Engine] manages a run that encompasses multiple test suites. | 21 /// An [Engine] manages a run that encompasses multiple test suites. |
23 /// | 22 /// |
24 /// Test suites are provided by passing them into [suiteSink]. Once all suites | 23 /// Test suites are provided by passing them into [suiteSink]. Once all suites |
25 /// have been provided, the user should close [suiteSink] to indicate this. | 24 /// have been provided, the user should close [suiteSink] to indicate this. |
26 /// [run] won't terminate until [suiteSink] is closed. Suites will be run in the | 25 /// [run] won't terminate until [suiteSink] is closed. Suites will be run in the |
27 /// order they're provided to [suiteSink]. Tests within those suites will | 26 /// order they're provided to [suiteSink]. Tests within those suites will |
28 /// likewise be run in the order of [Suite.tests]. | 27 /// likewise be run in the order of [Suite.tests]. |
29 /// | 28 /// |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 /// The tests that are still running, in the order they begain running. | 128 /// The tests that are still running, in the order they begain running. |
130 List<LiveTest> get active => new UnmodifiableListView(_active); | 129 List<LiveTest> get active => new UnmodifiableListView(_active); |
131 final _active = new QueueList<LiveTest>(); | 130 final _active = new QueueList<LiveTest>(); |
132 | 131 |
133 /// The tests from [LoadSuite]s that are still running, in the order they | 132 /// The tests from [LoadSuite]s that are still running, in the order they |
134 /// began running. | 133 /// began running. |
135 /// | 134 /// |
136 /// This is separate from [active] because load tests aren't always surfaced. | 135 /// This is separate from [active] because load tests aren't always surfaced. |
137 final _activeLoadTests = new List<LiveTest>(); | 136 final _activeLoadTests = new List<LiveTest>(); |
138 | 137 |
| 138 /// Whether this engine is idle—that is, not currently executing a test. |
| 139 bool get isIdle => _group.isIdle; |
| 140 |
| 141 /// A broadcast stream that fires an event whenever [isIdle] switches from |
| 142 /// `false` to `true`. |
| 143 Stream get onIdle => _group.onIdle; |
| 144 |
139 /// Creates an [Engine] that will run all tests provided via [suiteSink]. | 145 /// Creates an [Engine] that will run all tests provided via [suiteSink]. |
140 /// | 146 /// |
141 /// [concurrency] controls how many suites are run at once, and defaults to 1. | 147 /// [concurrency] controls how many suites are run at once, and defaults to 1. |
142 /// [maxSuites] controls how many suites are *loaded* at once, and defaults to | 148 /// [maxSuites] controls how many suites are *loaded* at once, and defaults to |
143 /// four times [concurrency]. | 149 /// four times [concurrency]. |
144 Engine({int concurrency, int maxSuites}) | 150 Engine({int concurrency, int maxSuites}) |
145 : _runPool = new Pool(concurrency == null ? 1 : concurrency), | 151 : _runPool = new Pool(concurrency == null ? 1 : concurrency), |
146 _loadPool = new Pool(maxSuites == null | 152 _loadPool = new Pool(maxSuites == null |
147 ? (concurrency == null ? 2 : concurrency * 2) | 153 ? (concurrency == null ? 2 : concurrency * 2) |
148 : maxSuites) { | 154 : maxSuites) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 325 |
320 // Close the running tests first so that we're sure to wait for them to | 326 // Close the running tests first so that we're sure to wait for them to |
321 // finish before we close their suites and cause them to become unloaded. | 327 // finish before we close their suites and cause them to become unloaded. |
322 var allLiveTests = liveTests.toSet()..addAll(_activeLoadTests); | 328 var allLiveTests = liveTests.toSet()..addAll(_activeLoadTests); |
323 await Future.wait(allLiveTests.map((liveTest) => liveTest.close())); | 329 await Future.wait(allLiveTests.map((liveTest) => liveTest.close())); |
324 | 330 |
325 var allSuites = allLiveTests.map((liveTest) => liveTest.suite).toSet(); | 331 var allSuites = allLiveTests.map((liveTest) => liveTest.suite).toSet(); |
326 await Future.wait(allSuites.map((suite) => suite.close())); | 332 await Future.wait(allSuites.map((suite) => suite.close())); |
327 } | 333 } |
328 } | 334 } |
OLD | NEW |