From a33ff27ba873a61416261a99e7073443ab6de0ff Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 30 Sep 2025 11:06:57 -0400 Subject: [PATCH] Retry `xcodebuild` by rebooting simulator when stuck When `xcodebuild` times out waiting for tests to start, reboot the simulator and retry up to 3 times before failing. This handles intermittent issues where the simulator gets into a bad state. --- xctestrunner/test_runner/xcodebuild_test_executor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xctestrunner/test_runner/xcodebuild_test_executor.py b/xctestrunner/test_runner/xcodebuild_test_executor.py index 56b5fcb..db987c6 100644 --- a/xctestrunner/test_runner/xcodebuild_test_executor.py +++ b/xctestrunner/test_runner/xcodebuild_test_executor.py @@ -211,6 +211,16 @@ def Execute(self, return_output=True, result_bundle_path=None): check_xcodebuild_stuck.Terminate() if check_xcodebuild_stuck.is_xcodebuild_stuck: + if self._sdk == ios_constants.SDK.IPHONESIMULATOR and i < max_attempts - 1: + logging.warning( + 'xcodebuild stuck on simulator (attempt %d/%d). ' + 'Will reboot simulator and retry.', + i + 1, max_attempts) + simulator = simulator_util.Simulator(self._device_id) + simulator.Shutdown() + simulator.Boot() + time.sleep(2) + continue return self._GetResultForXcodebuildStuck(output, return_output) output_str = output.getvalue()