Skip to content

[coverage] Fix resume after shutdown error #2079

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 5 commits into from
Apr 29, 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
4 changes: 3 additions & 1 deletion pkgs/coverage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 1.13.0-wip
## 1.13.0

- Introduced support for minimum coverage thresholds using --fail-under flag in
format_coverage.
- Fix a bug where we attempt to resume an isolate after the VM service has been
shut down.

## 1.12.0

Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Coverage provides coverage data collection, manipulation, and formatting for
Dart.

[![Build Status](https://github.com/dart-lang/tools/actions/workflows/coverage.yml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/coverage.yml)
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/coverage.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/coverage.yaml)
[![Coverage Status](https://coveralls.io/repos/github/dart-lang/tools/badge.svg?branch=main)](https://coveralls.io/github/dart-lang/tools?branch=main)
[![Pub](https://img.shields.io/pub/v/coverage.svg)](https://pub.dev/packages/coverage)

Expand Down
6 changes: 4 additions & 2 deletions pkgs/coverage/lib/src/isolate_paused_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ class IsolatePausedListener {
} else {
final isLastIsolateInGroup = group.noRunningIsolates;
if (isLastIsolateInGroup) {
_getGroup(isolateRef).collected = true;
group.collected = true;
}
try {
await _onIsolatePaused(isolateRef, isLastIsolateInGroup);
} finally {
group.exit(isolateRef);
await _service.resume(isolateRef.id!);
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-wip
version: 1.13.0
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
40 changes: 40 additions & 0 deletions pkgs/coverage/test/isolate_paused_listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ void main() {
late Future<void> allIsolatesExited;

late List<String> received;
Future<void> Function(String)? delayTheOnPauseCallback;
late bool stopped;

void startEvent(String id, String groupId, [String? name]) =>
Expand Down Expand Up @@ -522,6 +523,7 @@ void main() {
when(service.getVM()).thenAnswer((_) async => VM());

received = <String>[];
delayTheOnPauseCallback = null;
when(service.resume(any)).thenAnswer((invocation) async {
final id = invocation.positionalArguments[0];
received.add('Resume $id');
Expand All @@ -535,6 +537,10 @@ void main() {
expect(stopped, isFalse);
received.add('Pause ${iso.id}. Collect group ${iso.isolateGroupId}? '
'${isLastIsolateInGroup ? 'Yes' : 'No'}');
if (delayTheOnPauseCallback != null) {
await delayTheOnPauseCallback!(iso.id!);
received.add('Pause done ${iso.id}');
}
},
(message) => received.add(message),
).waitUntilAllExited();
Expand Down Expand Up @@ -849,5 +855,39 @@ void main() {
'Resume C',
]);
});

test('main isolate paused during other isolate pause callback', () async {
final delayingB = Completer<void>();
delayTheOnPauseCallback = (String isoId) async {
if (isoId == 'B') await delayingB.future;
};

startEvent('A', '1', 'main');
startEvent('B', '2');
pauseEvent('B', '2');
pauseEvent('A', '1', 'main');

while (received.length < 4) {
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();
await endTest();
expect(received, [
'Pause B. Collect group 2? Yes',
'Pause A. Collect group 1? Yes',
'Pause done A',
'Resume A',
'Pause done B',
// Don't try to resume B, because the VM service is already shut down.
]);
});
});
}