From f77c669d687c11d6aca81f053bbf028adc59794e Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 27 May 2020 12:47:30 -0700 Subject: [PATCH] [flutter_tools] write test to convince self of lack of timing issue (#58011) In #55864 a race condition was described where a done event is received before we finish connecting. This cannot happen, since async functions begin synchronously and the flag isWaitingForVm is tripped immediately, keeping onDone from exiting. --- .../general.shard/resident_runner_test.dart | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 319df1a121..040ed0ef0c 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -1198,6 +1198,48 @@ void main() { }) async => mockVMService, })); + group('Timing test', () { + Completer completer; + + test('Can connect to observatory stream after receiving done event.', () => testbed.run(() async { + completer = Completer(); + fakeVmServiceHost = FakeVmServiceHost(requests: []); + final MockDevice mockDevice = MockDevice(); + final MockDeviceLogReader mockLogReader = MockDeviceLogReader(); + when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(mockLogReader); + final StreamController controller = StreamController(); + + final TestFlutterDevice flutterDevice = TestFlutterDevice( + mockDevice, + observatoryUris: controller.stream, + ); + + final Future connectResult = flutterDevice.connect(); + + // First add the observatory URI to connect to. + controller.add(testUri); + + // Then close the stream. + await controller.close(); + + // Then complete the VM service connection. + completer.complete(mockVMService); + + await connectResult; + + verify(mockLogReader.connectedVMService = mockVMService); + }, overrides: { + VMServiceConnector: () => (Uri httpUri, { + ReloadSources reloadSources, + Restart restart, + CompileExpression compileExpression, + ReloadMethod reloadMethod, + io.CompressionOptions compression, + Device device, + }) async => completer.future, + })); + }); + test('nextPlatform moves through expected platforms', () { expect(nextPlatform('android', TestFeatureFlags()), 'iOS'); expect(nextPlatform('iOS', TestFeatureFlags()), 'fuchsia');