From 5fb34b719e951cb2e5b38c7ca905e405a1159c93 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Thu, 6 Jun 2024 16:22:51 -0700 Subject: [PATCH] Attempt to fix some web test flakiness. (#149828) If the service is disposed when we make calls on it, we need to bubble up an exception that is understood by the callers. This is another speculative fix for https://github.com/flutter/flutter/issues/149238. --- packages/flutter_tools/lib/src/vmservice.dart | 3 +++ .../test/general.shard/vmservice_test.dart | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 72d61a8f6d2a..1a66b17ede89 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -989,6 +989,9 @@ class FlutterVmService { } } return await extensionAdded.future; + } on vm_service.RPCError { + // Translate this exception into something the outer layer understands + throw VmServiceDisappearedException(); } finally { await isolateEvents.cancel(); try { diff --git a/packages/flutter_tools/test/general.shard/vmservice_test.dart b/packages/flutter_tools/test/general.shard/vmservice_test.dart index a141d347ec4b..700c192914a0 100644 --- a/packages/flutter_tools/test/general.shard/vmservice_test.dart +++ b/packages/flutter_tools/test/general.shard/vmservice_test.dart @@ -789,6 +789,17 @@ void main() { throwsA(isA()), ); }); + + testWithoutContext('throws when the service is disposed', () async { + final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: []); + + await fakeVmServiceHost.vmService.dispose(); + + expect( + () => fakeVmServiceHost.vmService.findExtensionIsolate(kExtensionName), + throwsA(isA()), + ); + }); }); testWithoutContext('Can process log events from the vm service', () {