| 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; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 /// The tests that are still running, in the order they begain running. | 131 /// The tests that are still running, in the order they begain running. |
| 132 List<LiveTest> get active => new UnmodifiableListView(_active); | 132 List<LiveTest> get active => new UnmodifiableListView(_active); |
| 133 final _active = new QueueList<LiveTest>(); | 133 final _active = new QueueList<LiveTest>(); |
| 134 | 134 |
| 135 /// The set of tests that have completed successfully but shouldn't be | 135 /// The set of tests that have completed successfully but shouldn't be |
| 136 /// displayed by the reporter. | 136 /// displayed by the reporter. |
| 137 /// | 137 /// |
| 138 /// This includes load tests, `setUpAll`, and `tearDownAll`. | 138 /// This includes load tests, `setUpAll`, and `tearDownAll`. |
| 139 final _hidden = new Set<LiveTest>(); | 139 final _hidden = new Set<LiveTest>(); |
| 140 | 140 |
| 141 /// The set of tests that have been marked for restarting. |
| 142 /// |
| 143 /// This is always a subset of [active]. Once a test in here has finished |
| 144 /// running, it's run again. |
| 145 final _restarted = new Set<LiveTest>(); |
| 146 |
| 141 /// The tests from [LoadSuite]s that are still running, in the order they | 147 /// The tests from [LoadSuite]s that are still running, in the order they |
| 142 /// began running. | 148 /// began running. |
| 143 /// | 149 /// |
| 144 /// This is separate from [active] because load tests aren't always surfaced. | 150 /// This is separate from [active] because load tests aren't always surfaced. |
| 145 final _activeLoadTests = new List<LiveTest>(); | 151 final _activeLoadTests = new List<LiveTest>(); |
| 146 | 152 |
| 147 /// Whether this engine is idle—that is, not currently executing a test. | 153 /// Whether this engine is idle—that is, not currently executing a test. |
| 148 bool get isIdle => _group.isIdle; | 154 bool get isIdle => _group.isIdle; |
| 149 | 155 |
| 150 /// A broadcast stream that fires an event whenever [isIdle] switches from | 156 /// A broadcast stream that fires an event whenever [isIdle] switches from |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 }); | 323 }); |
| 318 | 324 |
| 319 _onTestStartedController.add(liveTest); | 325 _onTestStartedController.add(liveTest); |
| 320 | 326 |
| 321 // First, schedule a microtask to ensure that [onTestStarted] fires before | 327 // First, schedule a microtask to ensure that [onTestStarted] fires before |
| 322 // the first [LiveTest.onStateChange] event. Once the test finishes, use | 328 // the first [LiveTest.onStateChange] event. Once the test finishes, use |
| 323 // [new Future] to do a coarse-grained event loop pump to avoid starving | 329 // [new Future] to do a coarse-grained event loop pump to avoid starving |
| 324 // non-microtask events. | 330 // non-microtask events. |
| 325 await new Future.microtask(liveTest.run); | 331 await new Future.microtask(liveTest.run); |
| 326 await new Future(() {}); | 332 await new Future(() {}); |
| 333 |
| 334 if (!_restarted.contains(liveTest)) return; |
| 335 await _runLiveTest(liveTest.copy(), countSuccess: countSuccess); |
| 336 _restarted.remove(liveTest); |
| 337 } |
| 338 |
| 339 /// Closes [liveTest] and tells the engine to re-run it once it's done |
| 340 /// running. |
| 341 /// |
| 342 /// Returns the same future as [LiveTest.close]. |
| 343 Future restartTest(LiveTest liveTest) async { |
| 344 if (_activeLoadTests.contains(liveTest)) { |
| 345 throw new ArgumentError("Can't restart a load test."); |
| 346 } |
| 347 |
| 348 if (!_active.contains(liveTest)) { |
| 349 throw new StateError("Can't restart inactive test " |
| 350 "\"${liveTest.test.name}\"."); |
| 351 } |
| 352 |
| 353 _restarted.add(liveTest); |
| 354 _active.remove(liveTest); |
| 355 await liveTest.close(); |
| 327 } | 356 } |
| 328 | 357 |
| 329 /// Adds listeners for [suite]. | 358 /// Adds listeners for [suite]. |
| 330 /// | 359 /// |
| 331 /// Load suites have specific logic apart from normal test suites. | 360 /// Load suites have specific logic apart from normal test suites. |
| 332 Future<RunnerSuite> _addLoadSuite(LoadSuite suite) async { | 361 Future<RunnerSuite> _addLoadSuite(LoadSuite suite) async { |
| 333 var liveTest = await suite.test.load(suite); | 362 var liveTest = await suite.test.load(suite); |
| 334 | 363 |
| 335 _activeLoadTests.add(liveTest); | 364 _activeLoadTests.add(liveTest); |
| 336 | 365 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 var futures = allLiveTests.map((liveTest) => liveTest.close()).toList(); | 426 var futures = allLiveTests.map((liveTest) => liveTest.close()).toList(); |
| 398 | 427 |
| 399 // Closing the load pool will close the test suites as soon as their tests | 428 // Closing the load pool will close the test suites as soon as their tests |
| 400 // are done. For browser suites this is effectively immediate since their | 429 // are done. For browser suites this is effectively immediate since their |
| 401 // tests shut down as soon as they're closed, but for VM suites we may need | 430 // tests shut down as soon as they're closed, but for VM suites we may need |
| 402 // to wait for tearDowns or tearDownAlls to run. | 431 // to wait for tearDowns or tearDownAlls to run. |
| 403 futures.add(_loadPool.close()); | 432 futures.add(_loadPool.close()); |
| 404 await Future.wait(futures, eagerError: true); | 433 await Future.wait(futures, eagerError: true); |
| 405 } | 434 } |
| 406 } | 435 } |
| OLD | NEW |