Skip to content

Commit 02e3ec4

Browse files
committed
Stop putting suite loads into active test
Towards #1311 Removes a UX concern from `Engine` which no longer needs to worry about how a reporter might display information about load suites. Makes the interaction between the engine and reporters less subtle. Use the term "suite load" over "load test" to start pushing terminology away from conflating tests and loading.
1 parent 05d7dd1 commit 02e3ec4

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

pkgs/test_core/lib/src/runner/engine.dart

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ import 'util/iterable_set.dart';
3636
///
3737
/// The engine has some special logic for [LoadSuite]s and the tests they
3838
/// contain, referred to as "load tests". Load tests exist to provide visibility
39-
/// into the process of loading test files, but as long as that process is
40-
/// proceeding normally users usually don't care about it, so the engine only
41-
/// surfaces running load tests (that is, includes them in [liveTests] and other
42-
/// collections) under specific circumstances.
43-
///
44-
/// If only load tests are running, exactly one load test will be in [active]
45-
/// and [liveTests]. If this test passes, it will be removed from both [active]
46-
/// and [liveTests] and *will not* be added to [passed]. If at any point a load
47-
/// test fails, it will be added to [failed] and [liveTests].
39+
/// into the process of loading test files. As long as that process is
40+
/// proceeding normally users usually don't care about it, so the engine does
41+
/// not include them in [liveTests] and other collections.
42+
/// If a load test fails, it will be added to [failed] and [liveTests].
4843
///
4944
/// The test suite loaded by a load suite will be automatically be run by the
5045
/// engine; it doesn't need to be added to [suiteSink] manually.
@@ -174,22 +169,22 @@ class Engine {
174169
Set<LiveTest> get failed => _failedGroup.set;
175170
final _failedGroup = UnionSetController<LiveTest>(disjoint: true);
176171

177-
/// The tests that are still running, in the order they begain running.
172+
/// The tests that are still running, in the order they began running.
178173
List<LiveTest> get active => UnmodifiableListView(_active);
179174
final _active = QueueList<LiveTest>();
180175

176+
/// The tests from [LoadSuite]s that are still running, in the order they
177+
/// began running.
178+
List<LiveTest> get activeSuiteLoads =>
179+
UnmodifiableListView(_activeSuiteLoads);
180+
final _activeSuiteLoads = <LiveTest>{};
181+
181182
/// The set of tests that have been marked for restarting.
182183
///
183184
/// This is always a subset of [active]. Once a test in here has finished
184185
/// running, it's run again.
185186
final _restarted = <LiveTest>{};
186187

187-
/// The tests from [LoadSuite]s that are still running, in the order they
188-
/// began running.
189-
///
190-
/// This is separate from [active] because load tests aren't always surfaced.
191-
final _activeLoadTests = <LiveTest>{};
192-
193188
/// Whether this engine is idle—that is, not currently executing a test.
194189
bool get isIdle => _group.isIdle;
195190

@@ -356,21 +351,11 @@ class Engine {
356351
await _onUnpaused;
357352
_active.add(liveTest);
358353

359-
// If there were no active non-load tests, the current active test would
360-
// have been a load test. In that case, remove it, since now we have a
361-
// non-load test to add.
362-
if (_active.first.suite is LoadSuite) _active.removeFirst();
363-
364354
var subscription = liveTest.onStateChange.listen(null);
365355
subscription
366356
..onData((state) {
367357
if (state.status != Status.complete) return;
368358
_active.remove(liveTest);
369-
370-
// If we're out of non-load tests, surface a load test.
371-
if (_active.isEmpty && _activeLoadTests.isNotEmpty) {
372-
_active.add(_activeLoadTests.first);
373-
}
374359
})
375360
..onDone(() {
376361
_subscriptions.remove(subscription);
@@ -425,7 +410,7 @@ class Engine {
425410
///
426411
/// Returns the same future as [LiveTest.close].
427412
Future restartTest(LiveTest liveTest) async {
428-
if (_activeLoadTests.contains(liveTest)) {
413+
if (_activeSuiteLoads.contains(liveTest)) {
429414
throw ArgumentError("Can't restart a load test.");
430415
}
431416

@@ -447,24 +432,13 @@ class Engine {
447432
_addLiveSuite(controller.liveSuite);
448433

449434
var liveTest = suite.test.load(suite);
450-
_activeLoadTests.add(liveTest);
451-
452-
// Only surface the load test if there are no other tests currently running.
453-
if (_active.isEmpty) _active.add(liveTest);
435+
_activeSuiteLoads.add(liveTest);
454436

455437
var subscription = liveTest.onStateChange.listen(null);
456438
subscription
457439
..onData((state) {
458440
if (state.status != Status.complete) return;
459-
_activeLoadTests.remove(liveTest);
460-
461-
// Only one load test will be active at any given time, and it will always
462-
// be the only active test. Remove it and, if possible, surface another
463-
// load test.
464-
if (_active.isNotEmpty && _active.first.suite == suite) {
465-
_active.remove(liveTest);
466-
if (_activeLoadTests.isNotEmpty) _active.add(_activeLoadTests.last);
467-
}
441+
_activeSuiteLoads.remove(liveTest);
468442
})
469443
..onDone(() {
470444
_subscriptions.remove(subscription);
@@ -547,7 +521,7 @@ class Engine {
547521

548522
// Close the running tests first so that we're sure to wait for them to
549523
// finish before we close their suites and cause them to become unloaded.
550-
var allLiveTests = liveTests.toSet()..addAll(_activeLoadTests);
524+
var allLiveTests = liveTests.toSet()..addAll(_activeSuiteLoads);
551525
var futures = allLiveTests.map((liveTest) => liveTest.close()).toList();
552526

553527
// Closing the run pool will close the test suites as soon as their tests

pkgs/test_core/lib/src/runner/reporter/compact.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ class CompactReporter implements Reporter {
186186
.listen((_) => _progressLine(_lastProgressMessage ?? '')));
187187
}
188188

189-
// If this is the first test to start, print a progress line so the user
190-
// knows what's running. It's possible that the active test may not be
191-
// [liveTest] because the engine doesn't always surface load tests.
192-
if (_engine.active.length == 1 && _engine.active.first == liveTest) {
189+
// If this is the first test or suite load to start, print a progress line
190+
// so the user knows what's running.
191+
if ((_engine.active.length == 1 && _engine.active.first == liveTest) ||
192+
(_engine.liveTests.isEmpty &&
193+
_engine.activeSuiteLoads.length == 1 &&
194+
_engine.activeSuiteLoads.first == liveTest)) {
193195
_progressLine(_description(liveTest));
194196
}
195197

pkgs/test_core/lib/src/runner/reporter/expanded.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ class ExpandedReporter implements Reporter {
164164
// emit information about them unless they fail.
165165
_subscriptions.add(liveTest.onStateChange
166166
.listen((state) => _onStateChange(liveTest, state)));
167-
} else if (_engine.active.length == 1 &&
168-
_engine.active.first == liveTest &&
167+
} else if (_engine.active.isEmpty &&
168+
_engine.activeSuiteLoads.length == 1 &&
169+
_engine.activeSuiteLoads.first == liveTest &&
169170
liveTest.test.name.startsWith('compiling ')) {
170171
// Print a progress line for load tests that come from compiling JS, since
171172
// that takes a long time.

0 commit comments

Comments
 (0)