diff --git a/pkgs/coverage/lib/src/isolate_paused_listener.dart b/pkgs/coverage/lib/src/isolate_paused_listener.dart index 3ac5ca98b..a89a88b8a 100644 --- a/pkgs/coverage/lib/src/isolate_paused_listener.dart +++ b/pkgs/coverage/lib/src/isolate_paused_listener.dart @@ -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); } @@ -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(); } } diff --git a/pkgs/coverage/test/isolate_paused_listener_test.dart b/pkgs/coverage/test/isolate_paused_listener_test.dart index 5e86bec91..4fc7d4b12 100644 --- a/pkgs/coverage/test/isolate_paused_listener_test.dart +++ b/pkgs/coverage/test/isolate_paused_listener_test.dart @@ -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'); @@ -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');