fix(flutter_driver): Properly declare socket as nullable (#75769)
This commit is contained in:
committed by
GitHub
parent
e7953b3be4
commit
6db3d61ed4
@@ -561,7 +561,7 @@ String _getWebSocketUrl(String url) {
|
||||
Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic>? headers) async {
|
||||
final String webSocketUrl = _getWebSocketUrl(url);
|
||||
int attempts = 0;
|
||||
late WebSocket socket;
|
||||
WebSocket? socket;
|
||||
while (true) {
|
||||
try {
|
||||
socket = await WebSocket.connect(webSocketUrl, headers: headers);
|
||||
@@ -575,7 +575,7 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic>? headers)
|
||||
controller.stream,
|
||||
socket.add,
|
||||
log: null,
|
||||
disposeHandler: () => socket.close(),
|
||||
disposeHandler: () => socket!.close(),
|
||||
streamClosed: streamClosedCompleter.future
|
||||
);
|
||||
// This call is to ensure we are able to establish a connection instead of
|
||||
@@ -583,7 +583,7 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic>? headers)
|
||||
await service.getVersion();
|
||||
return service;
|
||||
} catch (e) {
|
||||
await socket.close();
|
||||
await socket?.close();
|
||||
if (attempts > 5) {
|
||||
_log('It is taking an unusually long time to connect to the VM...');
|
||||
}
|
||||
|
||||
@@ -52,6 +52,19 @@ void main() {
|
||||
restoreVmServiceConnectFunction();
|
||||
});
|
||||
|
||||
test('Retries while Dart VM service is not available', () async {
|
||||
// This test case will test the real implementation of `_waitAndConnect`.
|
||||
restoreVmServiceConnectFunction();
|
||||
|
||||
// The actual behavior is to retry indefinitely until the Dart VM service
|
||||
// becomes available. `.timeout` is used here to exit the infinite loop,
|
||||
// expecting that no other types of error are thrown during the process.
|
||||
expect(
|
||||
vmServiceConnectFunction('http://foo.bar', <String, dynamic>{})
|
||||
.timeout(const Duration(seconds: 1)),
|
||||
throwsA(isA<TimeoutException>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws after retries if no isolate', () async {
|
||||
fakeVM.numberOfTriesBeforeResolvingIsolate = 10000;
|
||||
|
||||
Reference in New Issue
Block a user