Skip to content

Commit

Permalink
Handle case where main is the only isolate
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Oct 4, 2024
1 parent 65d57c0 commit f4670dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pkgs/coverage/lib/src/isolate_paused_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class IsolatePausedListener {
group.pause(isolateRef.id!);
if (isolateRef.id! == _mainIsolate?.id) {
_mainIsolatePaused.complete(true);

// If the main isolate is the only isolate, then _allNonMainIsolatesExited
// will never be completed. So check that case here.
_checkCompleted();
} else {
await _runCallbackAndResume(isolateRef, group.noRunningIsolates);
}
Expand Down Expand Up @@ -106,9 +110,13 @@ class IsolatePausedListener {
}
} else {
--_numNonMainIsolates;
if (_numNonMainIsolates == 0 && !_allNonMainIsolatesExited.isCompleted) {
_allNonMainIsolatesExited.complete();
}
_checkCompleted();
}
}

void _checkCompleted() {
if (_numNonMainIsolates == 0 && !_allNonMainIsolatesExited.isCompleted) {
_allNonMainIsolatesExited.complete();
}
}

Expand Down
14 changes: 13 additions & 1 deletion pkgs/coverage/test/isolate_paused_listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ void main() {
startEvent('A', '1', 'main');
startEvent('B', '1', 'main'); // Second isolate named main, ignored.
pauseEvent('B', '1', 'main');
pauseEvent('A', '1', 'main');
startEvent('C', '2', 'main'); // Third isolate named main, ignored.
pauseEvent('A', '1', 'main');
startEvent('D', '2');
pauseEvent('C', '2');
exitEvent('C', '2');
Expand Down Expand Up @@ -667,6 +667,18 @@ void main() {
]);
});

test('main isolate is the only isolate', () async {
startEvent('A', '1', 'main');
pauseEvent('A', '1', 'main');

await endTest();

expect(received, [
'Pause A. Last in group 1? Yes',
'Resume A',
]);
});

test('all other isolates exit before main isolate pauses', () async {
startEvent('A', '1', 'main');
startEvent('B', '1');
Expand Down

0 comments on commit f4670dd

Please sign in to comment.