Skip to content

Commit 92f10a9

Browse files
authored
[coverage] Fix resume after shutdown error (#2079)
1 parent 7e8cb03 commit 92f10a9

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

pkgs/coverage/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## 1.13.0-wip
1+
## 1.13.0
22

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

68
## 1.12.0
79

pkgs/coverage/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Coverage provides coverage data collection, manipulation, and formatting for
22
Dart.
33

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

pkgs/coverage/lib/src/isolate_paused_listener.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ class IsolatePausedListener {
8989
} else {
9090
final isLastIsolateInGroup = group.noRunningIsolates;
9191
if (isLastIsolateInGroup) {
92-
_getGroup(isolateRef).collected = true;
92+
group.collected = true;
9393
}
9494
try {
9595
await _onIsolatePaused(isolateRef, isLastIsolateInGroup);
9696
} finally {
9797
group.exit(isolateRef);
98-
await _service.resume(isolateRef.id!);
98+
if (!_finishedListening) {
99+
await _service.resume(isolateRef.id!);
100+
}
99101
}
100102
}
101103
}

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-wip
2+
version: 1.13.0
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ void main() {
485485
late Future<void> allIsolatesExited;
486486

487487
late List<String> received;
488+
Future<void> Function(String)? delayTheOnPauseCallback;
488489
late bool stopped;
489490

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

524525
received = <String>[];
526+
delayTheOnPauseCallback = null;
525527
when(service.resume(any)).thenAnswer((invocation) async {
526528
final id = invocation.positionalArguments[0];
527529
received.add('Resume $id');
@@ -535,6 +537,10 @@ void main() {
535537
expect(stopped, isFalse);
536538
received.add('Pause ${iso.id}. Collect group ${iso.isolateGroupId}? '
537539
'${isLastIsolateInGroup ? 'Yes' : 'No'}');
540+
if (delayTheOnPauseCallback != null) {
541+
await delayTheOnPauseCallback!(iso.id!);
542+
received.add('Pause done ${iso.id}');
543+
}
538544
},
539545
(message) => received.add(message),
540546
).waitUntilAllExited();
@@ -849,5 +855,39 @@ void main() {
849855
'Resume C',
850856
]);
851857
});
858+
859+
test('main isolate paused during other isolate pause callback', () async {
860+
final delayingB = Completer<void>();
861+
delayTheOnPauseCallback = (String isoId) async {
862+
if (isoId == 'B') await delayingB.future;
863+
};
864+
865+
startEvent('A', '1', 'main');
866+
startEvent('B', '2');
867+
pauseEvent('B', '2');
868+
pauseEvent('A', '1', 'main');
869+
870+
while (received.length < 4) {
871+
await Future<void>.delayed(Duration.zero);
872+
}
873+
874+
expect(received, [
875+
'Pause B. Collect group 2? Yes',
876+
'Pause A. Collect group 1? Yes',
877+
'Pause done A',
878+
'Resume A',
879+
]);
880+
881+
delayingB.complete();
882+
await endTest();
883+
expect(received, [
884+
'Pause B. Collect group 2? Yes',
885+
'Pause A. Collect group 1? Yes',
886+
'Pause done A',
887+
'Resume A',
888+
'Pause done B',
889+
// Don't try to resume B, because the VM service is already shut down.
890+
]);
891+
});
852892
});
853893
}

0 commit comments

Comments
 (0)