diff --git a/scripts/gha/test_simulator.py b/scripts/gha/test_simulator.py index a1407a478c..d0dfed9663 100644 --- a/scripts/gha/test_simulator.py +++ b/scripts/gha/test_simulator.py @@ -419,6 +419,20 @@ def _delete_simulator(device_id): subprocess.run(args=args, check=True) +def _reset_simulator_on_error(device_id, type=_RESET_TYPE_REBOOT): + _shutdown_simulator() + + if type == _RESET_TYPE_WIPE_REBOOT: + args = ["xcrun", "simctl", "erase", device_id] + logging.info("Erase my simulator: %s", " ".join(args)) + subprocess.run(args=args, check=True) + + # reboot simulator: _RESET_TYPE_WIPE_REBOOT, _RESET_TYPE_REBOOT + args = ["xcrun", "simctl", "boot", device_id] + logging.info("Reboot my simulator: %s", " ".join(args)) + subprocess.run(args=args, check=True) + + def _get_bundle_id(app_path, config): """Get app bundle id from build_testapps.json file.""" for api in config["apis"]: @@ -446,14 +460,14 @@ def _install_apple_app(app_path, device_id): """Install integration_test app into the simulator.""" args = ["xcrun", "simctl", "install", device_id, app_path] logging.info("Install testapp: %s", " ".join(args)) - subprocess.run(args=args, check=True) + _run_with_retry(args, device=device_id, type=_RESET_TYPE_WIPE_REBOOT) def _uninstall_apple_app(bundle_id, device_id): """Uninstall integration_test app from the simulator.""" args = ["xcrun", "simctl", "uninstall", device_id, bundle_id] logging.info("Uninstall testapp: %s", " ".join(args)) - subprocess.run(args=args, check=True) + _run_with_retry(args, device=device_id, type=_RESET_TYPE_REBOOT) def _get_apple_test_log(bundle_id, app_path, device_id): @@ -562,17 +576,6 @@ def _create_and_boot_emulator(sdk_id): else: time.sleep(45) -def _run_with_retry(args, shell=False, check=True, timeout=_CMD_TIMEOUT, retry_time=_TEST_RETRY, device=_DEVICE_NONE, type=_RESET_TYPE_REBOOT): - if retry_time > 1: - try: - subprocess.run(args, shell=shell, check=check, timeout=timeout) - except: - if device == _DEVICE_ANDROID: - _reset_emulator_on_error(type) - _run_with_retry(args, shell, check, timeout, retry_time-1, device, type) - else: - subprocess.run(args, shell=shell, check=check, timeout=timeout) - def _reset_emulator_on_error(type=_RESET_TYPE_REBOOT): if type == _RESET_TYPE_WIPE_REBOOT: @@ -671,6 +674,25 @@ def _get_android_test_log(test_package): return result.stdout +def _run_with_retry(args, shell=False, check=True, timeout=_CMD_TIMEOUT, retry_time=_TEST_RETRY, device=_DEVICE_NONE, type=_RESET_TYPE_REBOOT): + logging.info("run_with_retry: %s; remaining retry: %s", args, retry_time) + if retry_time > 1: + try: + subprocess.run(args, shell=shell, check=check, timeout=timeout) + except: + if device == _DEVICE_NONE: + pass + elif device == _DEVICE_ANDROID: + # Android + _reset_emulator_on_error(type) + else: + # Apple + _reset_simulator_on_error(device, type) + _run_with_retry(args, shell, check, timeout, retry_time-1, device, type) + else: + subprocess.run(args, shell=shell, check=check, timeout=timeout) + + if __name__ == '__main__': flags.mark_flag_as_required("testapp_dir") app.run(main)