| 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 '../backend/live_test.dart'; | 10 import '../backend/live_test.dart'; |
| 11 import '../backend/state.dart'; | 11 import '../backend/state.dart'; |
| 12 import '../backend/suite.dart'; | 12 import '../backend/suite.dart'; |
| 13 import '../utils.dart'; | 13 import '../utils.dart'; |
| 14 | 14 |
| 15 /// An [Engine] manages a run that encompasses multiple test suites. | 15 /// An [Engine] manages a run that encompasses multiple test suites. |
| 16 /// | 16 /// |
| 17 /// The current status of every test is visible via [liveTests]. [onTestStarted] | 17 /// The current status of every test is visible via [liveTests]. [onTestStarted] |
| 18 /// can also be used to be notified when a test is about to be run. | 18 /// can also be used to be notified when a test is about to be run. |
| 19 /// | 19 /// |
| 20 /// Suites will be run in the order they're provided to [new Engine]. Tests | 20 /// Suites will be run in the order they're provided to [new Engine]. Tests |
| 21 /// within those suites will likewise be run in the order of [Suite.tests]. | 21 /// within those suites will likewise be run in the order of [Suite.tests]. |
| 22 class Engine { | 22 class Engine { |
| 23 /// Whether [run] has been called yet. | 23 /// Whether [run] has been called yet. |
| 24 var _runCalled = false; | 24 var _runCalled = false; |
| 25 | 25 |
| 26 /// Whether [close] has been called. |
| 27 var _closed = false; |
| 28 |
| 26 /// An unmodifiable list of tests to run. | 29 /// An unmodifiable list of tests to run. |
| 27 /// | 30 /// |
| 28 /// These are [LiveTest]s, representing the in-progress state of each test. | 31 /// These are [LiveTest]s, representing the in-progress state of each test. |
| 29 /// Tests that have not yet begun running are marked [Status.pending]; tests | 32 /// Tests that have not yet begun running are marked [Status.pending]; tests |
| 30 /// that have finished are marked [Status.complete]. | 33 /// that have finished are marked [Status.complete]. |
| 31 /// | 34 /// |
| 32 /// [LiveTest.run] must not be called on these tests. | 35 /// [LiveTest.run] must not be called on these tests. |
| 33 final List<LiveTest> liveTests; | 36 final List<LiveTest> liveTests; |
| 34 | 37 |
| 35 /// A stream that emits each [LiveTest] as it's about to start running. | 38 /// A stream that emits each [LiveTest] as it's about to start running. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 /// | 50 /// |
| 48 /// This returns `true` if all tests succeed, and `false` otherwise. It will | 51 /// This returns `true` if all tests succeed, and `false` otherwise. It will |
| 49 /// only return once all tests have finished running. | 52 /// only return once all tests have finished running. |
| 50 Future<bool> run() { | 53 Future<bool> run() { |
| 51 if (_runCalled) { | 54 if (_runCalled) { |
| 52 throw new StateError("Engine.run() may not be called more than once."); | 55 throw new StateError("Engine.run() may not be called more than once."); |
| 53 } | 56 } |
| 54 _runCalled = true; | 57 _runCalled = true; |
| 55 | 58 |
| 56 return Future.forEach(liveTests, (liveTest) { | 59 return Future.forEach(liveTests, (liveTest) { |
| 60 if (_closed) return new Future.value(); |
| 57 _onTestStartedController.add(liveTest); | 61 _onTestStartedController.add(liveTest); |
| 58 | 62 |
| 59 // First, schedule a microtask to ensure that [onTestStarted] fires before | 63 // First, schedule a microtask to ensure that [onTestStarted] fires before |
| 60 // the first [LiveTest.onStateChange] event. Once the test finishes, use | 64 // the first [LiveTest.onStateChange] event. Once the test finishes, use |
| 61 // [new Future] to do a coarse-grained event loop pump to avoid starving | 65 // [new Future] to do a coarse-grained event loop pump to avoid starving |
| 62 // the DOM or other non-microtask events. | 66 // the DOM or other non-microtask events. |
| 63 return new Future.microtask(liveTest.run).then((_) => new Future(() {})); | 67 return new Future.microtask(liveTest.run).then((_) => new Future(() {})); |
| 64 }).then((_) => | 68 }).then((_) => |
| 65 liveTests.every((liveTest) => liveTest.state.result == Result.success)); | 69 liveTests.every((liveTest) => liveTest.state.result == Result.success)); |
| 66 } | 70 } |
| 67 | 71 |
| 68 /// Signals that the caller is done paying attention to test results and the | 72 /// Signals that the caller is done paying attention to test results and the |
| 69 /// engine should release any resources it has allocated. | 73 /// engine should release any resources it has allocated. |
| 70 Future close() => | 74 /// |
| 71 Future.wait(liveTests.map((liveTest) => liveTest.close())); | 75 /// Any actively-running tests are also closed. VM tests are allowed to finish |
| 76 /// running so that any modifications they've made to the filesystem can be |
| 77 /// cleaned up. |
| 78 Future close() { |
| 79 _closed = true; |
| 80 return Future.wait(liveTests.map((liveTest) => liveTest.close())); |
| 81 } |
| 72 } | 82 } |
| OLD | NEW |