Skip to content

[coverage] Fix another flaky lifecycle management error #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/coverage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.13.1

- Fix a bug where the VM service can be shut down while some coverage
collections are still happening.

## 1.13.0

- Introduced support for minimum coverage thresholds using --fail-under flag in
Expand Down
9 changes: 7 additions & 2 deletions pkgs/coverage/lib/src/isolate_paused_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class IsolatePausedListener {
final SyncErrorLogger _log;

final _isolateGroups = <String, IsolateGroupState>{};
final _oldCollectionTasks = <Future<void>>{};

int _numIsolates = 0;
bool _finishedListening = false;
Expand All @@ -48,7 +49,7 @@ class IsolatePausedListener {
_finishedListening = true;

// Collect all remaining uncollected groups.
final collectionTasks = <Future<void>>[];
final collectionTasks = _oldCollectionTasks.toList();
for (final group in _isolateGroups.values) {
if (!group.collected) {
group.collected = true;
Expand Down Expand Up @@ -91,9 +92,13 @@ class IsolatePausedListener {
if (isLastIsolateInGroup) {
group.collected = true;
}
Future<void>? collectionTask;
try {
await _onIsolatePaused(isolateRef, isLastIsolateInGroup);
collectionTask = _onIsolatePaused(isolateRef, isLastIsolateInGroup);
_oldCollectionTasks.add(collectionTask);
await collectionTask;
} finally {
_oldCollectionTasks.remove(collectionTask);
group.exit(isolateRef);
if (!_finishedListening) {
await _service.resume(isolateRef.id!);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: coverage
version: 1.13.0
version: 1.13.1
description: Coverage data manipulation and formatting
repository: https://github.com/dart-lang/tools/tree/main/pkgs/coverage
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Acoverage
Expand Down
6 changes: 3 additions & 3 deletions pkgs/coverage/test/isolate_paused_listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -867,15 +867,14 @@ void main() {
pauseEvent('B', '2');
pauseEvent('A', '1', 'main');

while (received.length < 4) {
while (received.length < 3) {
await Future<void>.delayed(Duration.zero);
}

expect(received, [
'Pause B. Collect group 2? Yes',
'Pause A. Collect group 1? Yes',
'Pause done A',
'Resume A',
]);

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