Skip to content

Commit f1f8ac1

Browse files
authored
[coverage] Fix another flaky lifecycle management error (#2082)
1 parent 92f10a9 commit f1f8ac1

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

pkgs/coverage/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.13.1
2+
3+
- Fix a bug where the VM service can be shut down while some coverage
4+
collections are still happening.
5+
16
## 1.13.0
27

38
- Introduced support for minimum coverage thresholds using --fail-under flag in

pkgs/coverage/lib/src/isolate_paused_listener.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class IsolatePausedListener {
2727
final SyncErrorLogger _log;
2828

2929
final _isolateGroups = <String, IsolateGroupState>{};
30+
final _oldCollectionTasks = <Future<void>>{};
3031

3132
int _numIsolates = 0;
3233
bool _finishedListening = false;
@@ -48,7 +49,7 @@ class IsolatePausedListener {
4849
_finishedListening = true;
4950

5051
// Collect all remaining uncollected groups.
51-
final collectionTasks = <Future<void>>[];
52+
final collectionTasks = _oldCollectionTasks.toList();
5253
for (final group in _isolateGroups.values) {
5354
if (!group.collected) {
5455
group.collected = true;
@@ -91,9 +92,13 @@ class IsolatePausedListener {
9192
if (isLastIsolateInGroup) {
9293
group.collected = true;
9394
}
95+
Future<void>? collectionTask;
9496
try {
95-
await _onIsolatePaused(isolateRef, isLastIsolateInGroup);
97+
collectionTask = _onIsolatePaused(isolateRef, isLastIsolateInGroup);
98+
_oldCollectionTasks.add(collectionTask);
99+
await collectionTask;
96100
} finally {
101+
_oldCollectionTasks.remove(collectionTask);
97102
group.exit(isolateRef);
98103
if (!_finishedListening) {
99104
await _service.resume(isolateRef.id!);

pkgs/coverage/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: coverage
2-
version: 1.13.0
2+
version: 1.13.1
33
description: Coverage data manipulation and formatting
44
repository: https://github.com/dart-lang/tools/tree/main/pkgs/coverage
55
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Acoverage

pkgs/coverage/test/isolate_paused_listener_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,14 @@ void main() {
867867
pauseEvent('B', '2');
868868
pauseEvent('A', '1', 'main');
869869

870-
while (received.length < 4) {
870+
while (received.length < 3) {
871871
await Future<void>.delayed(Duration.zero);
872872
}
873873

874874
expect(received, [
875875
'Pause B. Collect group 2? Yes',
876876
'Pause A. Collect group 1? Yes',
877877
'Pause done A',
878-
'Resume A',
879878
]);
880879

881880
delayingB.complete();
@@ -884,8 +883,9 @@ void main() {
884883
'Pause B. Collect group 2? Yes',
885884
'Pause A. Collect group 1? Yes',
886885
'Pause done A',
887-
'Resume A',
888886
'Pause done B',
887+
// A waits for B's pause callback to complete before resuming.
888+
'Resume A',
889889
// Don't try to resume B, because the VM service is already shut down.
890890
]);
891891
});

0 commit comments

Comments
 (0)