[flutter_tools] remove timeout from iOS device startup (#81229)

This commit is contained in:
Jonah Williams 2021-04-29 22:49:02 -07:00 committed by GitHub
parent ace61f01ef
commit 001323a275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 7 deletions

View file

@ -312,6 +312,7 @@ class IOSDevice extends Device {
bool prebuiltApplication = false,
bool ipv6 = false,
String userIdentifier,
@visibleForTesting Duration discoveryTimeout,
}) async {
String packageId;
@ -426,13 +427,12 @@ class IOSDevice extends Device {
return LaunchResult.succeeded();
}
_logger.printTrace('Application launched on the device. Waiting for observatory port.');
Uri localUri;
try {
localUri = await observatoryDiscovery.uri.timeout(const Duration(seconds: 30));
} on TimeoutException {
await observatoryDiscovery.cancel();
}
_logger.printTrace('Application launched on the device. Waiting for observatory url.');
final Timer timer = Timer(discoveryTimeout ?? const Duration(seconds: 30), () {
_logger.printError('iOS Observatory not discovered after 30 seconds. This is taking much longer than expected...');
});
final Uri localUri = await observatoryDiscovery.uri;
timer.cancel();
if (localUri == null) {
iosDeployDebugger?.detach();
return LaunchResult.failed();

View file

@ -178,6 +178,47 @@ void main() {
expect(await device.stopApp(iosApp), false);
});
testWithoutContext('IOSDevice.startApp prints warning message if discovery takes longer than configured timeout', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
kAttachDebuggerCommand,
]);
final IOSDevice device = setUpIOSDevice(
processManager: processManager,
fileSystem: fileSystem,
logger: logger,
);
final IOSApp iosApp = PrebuiltIOSApp(
projectBundleId: 'app',
bundleName: 'Runner',
bundleDir: fileSystem.currentDirectory,
);
final FakeDeviceLogReader deviceLogReader = FakeDeviceLogReader();
device.portForwarder = const NoOpDevicePortForwarder();
device.setLogReader(iosApp, deviceLogReader);
// Start writing messages to the log reader.
Timer.run(() async {
await Future<void>.delayed(const Duration(milliseconds: 1));
deviceLogReader.addLine('Foo');
deviceLogReader.addLine('Observatory 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>{},
discoveryTimeout: Duration.zero,
);
expect(launchResult.started, true);
expect(launchResult.hasObservatory, true);
expect(await device.stopApp(iosApp), false);
expect(logger.errorText, contains('iOS Observatory not discovered after 30 seconds. This is taking much longer than expected...'));
});
testWithoutContext('IOSDevice.startApp succeeds in release mode', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[