Skip to content

Commit a6603a4

Browse files
authored
[coverage] Fix isolate resumption after service disposal (#1189)
1 parent 66afa68 commit a6603a4

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

pkgs/coverage/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
## 1.11.0
2+
3+
- Fix a [bug](https://github.com/dart-lang/tools/issues/685) where the tool
4+
would occasionally try to resume an isolate after the VM service had been
5+
disposed.
6+
17
## 1.10.0
28

3-
- Fix bug where tests involving multiple isolates never finish (#520).
9+
- Fix a [bug](https://github.com/dart-lang/tools/issues/520) where tests
10+
involving multiple isolates never finish.
411

512
## 1.9.2
613

pkgs/coverage/lib/src/isolate_paused_listener.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class IsolatePausedListener {
4646
try {
4747
if (_mainIsolate != null) {
4848
if (await _mainIsolatePaused.future) {
49-
await _runCallbackAndResume(_mainIsolate!, true);
49+
await _runCallbackAndResume(
50+
_mainIsolate!, !_getGroup(_mainIsolate!).collected);
5051
}
5152
}
5253
} finally {
@@ -114,8 +115,13 @@ class IsolatePausedListener {
114115
}
115116
}
116117

118+
bool get _mainRunning =>
119+
_mainIsolate != null && !_mainIsolatePaused.isCompleted;
120+
117121
void _checkCompleted() {
118-
if (_numNonMainIsolates == 0 && !_allNonMainIsolatesExited.isCompleted) {
122+
if (_numNonMainIsolates == 0 &&
123+
!_mainRunning &&
124+
!_allNonMainIsolatesExited.isCompleted) {
119125
_allNonMainIsolatesExited.complete();
120126
}
121127
}

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.10.0
2+
version: 1.11.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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,68 @@ void main() {
700700
]);
701701
});
702702

703+
test(
704+
'all other isolates exit before main isolate pauses, then main '
705+
'starts another isolate, then pauses before they exit', () async {
706+
startEvent('A', '1', 'main');
707+
startEvent('B', '1');
708+
pauseEvent('B', '1');
709+
exitEvent('B', '1');
710+
711+
await Future<void>.delayed(Duration.zero);
712+
713+
startEvent('C', '1');
714+
pauseEvent('C', '1');
715+
pauseEvent('A', '1', 'main');
716+
exitEvent('C', '1');
717+
718+
await Future<void>.delayed(Duration.zero);
719+
720+
exitEvent('A', '1', 'main');
721+
722+
await endTest();
723+
724+
expect(received, [
725+
'Pause B. Last in group 1? No',
726+
'Resume B',
727+
'Pause C. Last in group 1? No',
728+
'Resume C',
729+
'Pause A. Last in group 1? Yes',
730+
'Resume A',
731+
]);
732+
});
733+
734+
test(
735+
'all other isolates exit before main isolate pauses, then main '
736+
'starts another isolate, then pauses before they pause', () async {
737+
startEvent('A', '1', 'main');
738+
startEvent('B', '1');
739+
pauseEvent('B', '1');
740+
exitEvent('B', '1');
741+
742+
await Future<void>.delayed(Duration.zero);
743+
744+
startEvent('C', '1');
745+
pauseEvent('A', '1', 'main');
746+
pauseEvent('C', '1');
747+
exitEvent('C', '1');
748+
749+
await Future<void>.delayed(Duration.zero);
750+
751+
exitEvent('A', '1', 'main');
752+
753+
await endTest();
754+
755+
expect(received, [
756+
'Pause B. Last in group 1? No',
757+
'Resume B',
758+
'Pause C. Last in group 1? Yes',
759+
'Resume C',
760+
'Pause A. Last in group 1? No',
761+
'Resume A',
762+
]);
763+
});
764+
703765
test('group reopened', () async {
704766
// If an isolate is reported in a group after the group as believed to be
705767
// closed, reopen the group. This double counts some coverage, but at

0 commit comments

Comments
 (0)