Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a06926d

Browse files
authored
Make sure to finish the suite if all tests are skipped (#49339)
Fixes flutter/flutter#140481 Before this fix, if all tests are skipped, the `onDone` callback never fires, which means the recieve port never closes, which means the process just hangs indefinitely (and the success message is never printed).
1 parent 3ec42ce commit a06926d

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

testing/litetest/lib/src/test_suite.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,30 @@ class TestSuite {
4040
);
4141
}
4242
if (skip) {
43-
_logger.writeln('Test $name: Skipped');
43+
_logger.writeln('Test "$name": Skipped');
44+
_primeQueue();
4445
return;
4546
}
4647
_pushTest(name, body);
4748
}
4849

50+
void _primeQueue() {
51+
if (!_testQueuePrimed) {
52+
// All tests() must be added synchronously with main, so we can enqueue an
53+
// event to start all tests to run after main() is done.
54+
Timer.run(_startAllTests);
55+
_testQueuePrimed = true;
56+
}
57+
}
58+
4959
void _pushTest(
5060
String name,
5161
dynamic Function() body,
5262
) {
5363
final Test newTest = Test(name, body, logger: _logger);
5464
_testQueue.add(newTest);
5565
newTest.state = TestState.queued;
56-
if (!_testQueuePrimed) {
57-
// All tests() must be added synchronously with main, so we can enqueue an
58-
// event to start all tests to run after main() is done.
59-
Timer.run(_startAllTests);
60-
_testQueuePrimed = true;
61-
}
66+
_primeQueue();
6267
}
6368

6469
void _startAllTests() {
@@ -72,6 +77,10 @@ class TestSuite {
7277
});
7378
}
7479
_lifecycle.onStart();
80+
if (_testQueue.isEmpty) {
81+
_logger.writeln('All tests skipped.');
82+
_lifecycle.onDone(_testQueue);
83+
}
7584
}
7685
}
7786

testing/litetest/test/litetest_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:collection';
7+
import 'dart:isolate';
78

89
import 'package:async_helper/async_helper.dart';
910
import 'package:async_helper/async_minitest.dart';
@@ -13,6 +14,25 @@ import 'package:litetest/src/test_suite.dart';
1314
Future<void> main() async {
1415
asyncStart();
1516

17+
test('skip', () async {
18+
final StringBuffer buffer = StringBuffer();
19+
final TestLifecycle lifecycle = TestLifecycle();
20+
final TestSuite ts = TestSuite(
21+
logger: buffer,
22+
lifecycle: lifecycle,
23+
);
24+
25+
ts.test('Test', () {
26+
expect(1, equals(1));
27+
}, skip: true);
28+
final bool result = await lifecycle.result;
29+
30+
expect(result, true);
31+
expect(buffer.toString(), equals(
32+
'Test "Test": Skipped\nAll tests skipped.\n',
33+
));
34+
});
35+
1636
test('test', () async {
1737
final StringBuffer buffer = StringBuffer();
1838
final TestLifecycle lifecycle = TestLifecycle();
@@ -211,6 +231,8 @@ Test "Test3": Passed
211231
}
212232

213233
class TestLifecycle implements Lifecycle {
234+
final ReceivePort port = ReceivePort();
235+
214236
final Completer<bool> _testCompleter = Completer<bool>();
215237

216238
Future<bool> get result => _testCompleter.future;
@@ -225,5 +247,6 @@ class TestLifecycle implements Lifecycle {
225247
testsSucceeded = testsSucceeded && (t.state == TestState.succeeded);
226248
}
227249
_testCompleter.complete(testsSucceeded);
250+
port.close();
228251
}
229252
}

0 commit comments

Comments
 (0)