From 58056bbe74ebb26f7c1c7fde66fc9bef377e0f96 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 17 Sep 2021 19:18:03 -0700 Subject: [PATCH] Close the IntegrationTestTestDevice stream when the VM service shuts down (#90022) --- .../lib/src/test/integration_test_device.dart | 9 ++++++++- .../integration_test_device_test.dart | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/test/integration_test_device.dart b/packages/flutter_tools/lib/src/test/integration_test_device.dart index 41c34ec36e..5d7eec3045 100644 --- a/packages/flutter_tools/lib/src/test/integration_test_device.dart +++ b/packages/flutter_tools/lib/src/test/integration_test_device.dart @@ -97,7 +97,14 @@ class IntegrationTestTestDevice implements TestDevice { ); }); - unawaited(remoteMessages.pipe(controller.local.sink)); + remoteMessages.listen( + (String s) => controller.local.sink.add(s), + onError: (Object error, StackTrace stack) => controller.local.sink.addError(error, stack), + ); + unawaited(vmService.service.onDone.whenComplete( + () => controller.local.sink.close(), + )); + return controller.foreign; } diff --git a/packages/flutter_tools/test/general.shard/integration_test_device_test.dart b/packages/flutter_tools/test/general.shard/integration_test_device_test.dart index 2f8a028d02..a318ed9893 100644 --- a/packages/flutter_tools/test/general.shard/integration_test_device_test.dart +++ b/packages/flutter_tools/test/general.shard/integration_test_device_test.dart @@ -11,6 +11,7 @@ import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/test/integration_test_device.dart'; import 'package:flutter_tools/src/test/test_device.dart'; import 'package:flutter_tools/src/vmservice.dart'; +import 'package:stream_channel/stream_channel.dart'; import 'package:vm_service/vm_service.dart' as vm_service; import '../src/context.dart'; @@ -211,4 +212,21 @@ void main() { Device device, }) async => fakeVmServiceHost.vmService, }); + + testUsingContext('Can handle closing of the VM service', () async { + final StreamChannel channel = await testDevice.start('entrypointPath'); + await fakeVmServiceHost.vmService.dispose(); + expect(await channel.stream.isEmpty, true); + }, overrides: { + VMServiceConnector: () => (Uri httpUri, { + ReloadSources reloadSources, + Restart restart, + CompileExpression compileExpression, + GetSkSLMethod getSkSLMethod, + PrintStructuredErrorLogMethod printStructuredErrorLogMethod, + io.CompressionOptions compression, + Device device, + Logger logger, + }) async => fakeVmServiceHost.vmService, + }); }