From 001323a2751fd98f916306b46806737d63347556 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 29 Apr 2021 22:49:02 -0700 Subject: [PATCH] [flutter_tools] remove timeout from iOS device startup (#81229) --- .../flutter_tools/lib/src/ios/devices.dart | 14 +++---- .../ios/ios_device_start_prebuilt_test.dart | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 4d346624f1..49fbb5f5e9 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -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(); diff --git a/packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart index 8dd196f254..35e835146c 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart @@ -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([ + 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.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: {}, + 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([