Unverified Commit 82bc9ca3 authored by Victoria Ashworth's avatar Victoria Ashworth Committed by GitHub

If one method of finding Dart VM fails for CoreDevice, wait for the other method (#139754)

For CoreDevices we use a combination of mDNS and device logs to find the Dart VM url. If mDNS fails first, it will cause the launch to fail even though the device logs may be able to find the url. So if one of the methods fails, wait for the other method before failing the launch.

Fixes https://github.com/flutter/flutter/issues/139685.
parent 0c0b77f3
......@@ -680,6 +680,14 @@ class IOSDevice extends Device {
localUri = await Future.any(
<Future<Uri?>>[vmUrlFromMDns, vmUrlFromLogs]
);
// If the first future to return is null, wait for the other to complete.
if (localUri == null) {
final List<Uri?> vmUrls = await Future.wait(
<Future<Uri?>>[vmUrlFromMDns, vmUrlFromLogs]
);
localUri = vmUrls.where((Uri? vmUrl) => vmUrl != null).firstOrNull;
}
} else {
localUri = await vmServiceDiscovery?.uri;
// If the `ios-deploy` debugger loses connection before it finds the
......
......@@ -904,6 +904,68 @@ void main() {
}, overrides: <Type, Generator>{
MDnsVmServiceDiscovery: () => FakeMDnsVmServiceDiscovery(),
});
group('IOSDevice.startApp attaches in debug mode via device logging', () {
late FakeMDnsVmServiceDiscovery mdnsDiscovery;
setUp(() {
mdnsDiscovery = FakeMDnsVmServiceDiscovery(returnsNull: true);
});
testUsingContext('when mDNS fails', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final FakeProcessManager processManager = FakeProcessManager.empty();
final Directory temporaryXcodeProjectDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_empty_xcode.rand0');
final Directory bundleLocation = fileSystem.currentDirectory;
final IOSDevice device = setUpIOSDevice(
processManager: processManager,
fileSystem: fileSystem,
isCoreDevice: true,
coreDeviceControl: FakeIOSCoreDeviceControl(),
xcodeDebug: FakeXcodeDebug(
expectedProject: XcodeDebugProject(
scheme: 'Runner',
xcodeWorkspace: temporaryXcodeProjectDirectory.childDirectory('Runner.xcworkspace'),
xcodeProject: temporaryXcodeProjectDirectory.childDirectory('Runner.xcodeproj'),
hostAppProjectName: 'Runner',
),
expectedDeviceId: '123',
expectedLaunchArguments: <String>['--enable-dart-profiling'],
expectedBundlePath: bundleLocation.path,
)
);
final IOSApp iosApp = PrebuiltIOSApp(
projectBundleId: 'app',
bundleName: 'Runner',
uncompressedBundle: bundleLocation,
applicationPackage: bundleLocation,
);
final FakeDeviceLogReader deviceLogReader = FakeDeviceLogReader();
device.portForwarder = const NoOpDevicePortForwarder();
device.setLogReader(iosApp, deviceLogReader);
unawaited(mdnsDiscovery.completer.future.whenComplete(() {
// Start writing messages to the log reader.
Timer.run(() {
deviceLogReader.addLine('Foo');
deviceLogReader.addLine('The Dart VM service is listening on http://127.0.0.1:456');
});
}));
final LaunchResult launchResult = await device.startApp(iosApp,
prebuiltApplication: true,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
platformArgs: <String, dynamic>{},
);
expect(launchResult.started, true);
expect(launchResult.hasVmService, true);
expect(await device.stopApp(iosApp), true);
}, overrides: <Type, Generator>{
MDnsVmServiceDiscovery: () => mdnsDiscovery,
});
});
});
});
}
......@@ -974,6 +1036,10 @@ class FakeDevicePortForwarder extends Fake implements DevicePortForwarder {
}
class FakeMDnsVmServiceDiscovery extends Fake implements MDnsVmServiceDiscovery {
FakeMDnsVmServiceDiscovery({this.returnsNull = false});
bool returnsNull;
Completer<void> completer = Completer<void>();
@override
Future<Uri?> getVMServiceUriForLaunch(
String applicationId,
......@@ -984,6 +1050,11 @@ class FakeMDnsVmServiceDiscovery extends Fake implements MDnsVmServiceDiscovery
bool useDeviceIPAsHost = false,
Duration timeout = Duration.zero,
}) async {
completer.complete();
if (returnsNull) {
return null;
}
return Uri.tryParse('http://0.0.0.0:1234');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment