Skip to content

Commit f77c669

Browse files
[flutter_tools] write test to convince self of lack of timing issue (flutter#58011)
In flutter#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.
1 parent 27e652c commit f77c669

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/flutter_tools/test/general.shard/resident_runner_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,48 @@ void main() {
11981198
}) async => mockVMService,
11991199
}));
12001200

1201+
group('Timing test', () {
1202+
Completer<MockVMService> completer;
1203+
1204+
test('Can connect to observatory stream after receiving done event.', () => testbed.run(() async {
1205+
completer = Completer<MockVMService>();
1206+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1207+
final MockDevice mockDevice = MockDevice();
1208+
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
1209+
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(mockLogReader);
1210+
final StreamController<Uri> controller = StreamController<Uri>();
1211+
1212+
final TestFlutterDevice flutterDevice = TestFlutterDevice(
1213+
mockDevice,
1214+
observatoryUris: controller.stream,
1215+
);
1216+
1217+
final Future<void> connectResult = flutterDevice.connect();
1218+
1219+
// First add the observatory URI to connect to.
1220+
controller.add(testUri);
1221+
1222+
// Then close the stream.
1223+
await controller.close();
1224+
1225+
// Then complete the VM service connection.
1226+
completer.complete(mockVMService);
1227+
1228+
await connectResult;
1229+
1230+
verify(mockLogReader.connectedVMService = mockVMService);
1231+
}, overrides: <Type, Generator>{
1232+
VMServiceConnector: () => (Uri httpUri, {
1233+
ReloadSources reloadSources,
1234+
Restart restart,
1235+
CompileExpression compileExpression,
1236+
ReloadMethod reloadMethod,
1237+
io.CompressionOptions compression,
1238+
Device device,
1239+
}) async => completer.future,
1240+
}));
1241+
});
1242+
12011243
test('nextPlatform moves through expected platforms', () {
12021244
expect(nextPlatform('android', TestFeatureFlags()), 'iOS');
12031245
expect(nextPlatform('iOS', TestFeatureFlags()), 'fuchsia');

0 commit comments

Comments
 (0)