Skip to content

Commit 96bfd28

Browse files
authored
If simulator install ios app failed, reset simulator and try again (#733)
1 parent 9efb188 commit 96bfd28

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

scripts/gha/test_simulator.py

+35-13
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,20 @@ def _delete_simulator(device_id):
419419
subprocess.run(args=args, check=True)
420420

421421

422+
def _reset_simulator_on_error(device_id, type=_RESET_TYPE_REBOOT):
423+
_shutdown_simulator()
424+
425+
if type == _RESET_TYPE_WIPE_REBOOT:
426+
args = ["xcrun", "simctl", "erase", device_id]
427+
logging.info("Erase my simulator: %s", " ".join(args))
428+
subprocess.run(args=args, check=True)
429+
430+
# reboot simulator: _RESET_TYPE_WIPE_REBOOT, _RESET_TYPE_REBOOT
431+
args = ["xcrun", "simctl", "boot", device_id]
432+
logging.info("Reboot my simulator: %s", " ".join(args))
433+
subprocess.run(args=args, check=True)
434+
435+
422436
def _get_bundle_id(app_path, config):
423437
"""Get app bundle id from build_testapps.json file."""
424438
for api in config["apis"]:
@@ -446,14 +460,14 @@ def _install_apple_app(app_path, device_id):
446460
"""Install integration_test app into the simulator."""
447461
args = ["xcrun", "simctl", "install", device_id, app_path]
448462
logging.info("Install testapp: %s", " ".join(args))
449-
subprocess.run(args=args, check=True)
463+
_run_with_retry(args, device=device_id, type=_RESET_TYPE_WIPE_REBOOT)
450464

451465

452466
def _uninstall_apple_app(bundle_id, device_id):
453467
"""Uninstall integration_test app from the simulator."""
454468
args = ["xcrun", "simctl", "uninstall", device_id, bundle_id]
455469
logging.info("Uninstall testapp: %s", " ".join(args))
456-
subprocess.run(args=args, check=True)
470+
_run_with_retry(args, device=device_id, type=_RESET_TYPE_REBOOT)
457471

458472

459473
def _get_apple_test_log(bundle_id, app_path, device_id):
@@ -562,17 +576,6 @@ def _create_and_boot_emulator(sdk_id):
562576
else:
563577
time.sleep(45)
564578

565-
def _run_with_retry(args, shell=False, check=True, timeout=_CMD_TIMEOUT, retry_time=_TEST_RETRY, device=_DEVICE_NONE, type=_RESET_TYPE_REBOOT):
566-
if retry_time > 1:
567-
try:
568-
subprocess.run(args, shell=shell, check=check, timeout=timeout)
569-
except:
570-
if device == _DEVICE_ANDROID:
571-
_reset_emulator_on_error(type)
572-
_run_with_retry(args, shell, check, timeout, retry_time-1, device, type)
573-
else:
574-
subprocess.run(args, shell=shell, check=check, timeout=timeout)
575-
576579

577580
def _reset_emulator_on_error(type=_RESET_TYPE_REBOOT):
578581
if type == _RESET_TYPE_WIPE_REBOOT:
@@ -671,6 +674,25 @@ def _get_android_test_log(test_package):
671674
return result.stdout
672675

673676

677+
def _run_with_retry(args, shell=False, check=True, timeout=_CMD_TIMEOUT, retry_time=_TEST_RETRY, device=_DEVICE_NONE, type=_RESET_TYPE_REBOOT):
678+
logging.info("run_with_retry: %s; remaining retry: %s", args, retry_time)
679+
if retry_time > 1:
680+
try:
681+
subprocess.run(args, shell=shell, check=check, timeout=timeout)
682+
except:
683+
if device == _DEVICE_NONE:
684+
pass
685+
elif device == _DEVICE_ANDROID:
686+
# Android
687+
_reset_emulator_on_error(type)
688+
else:
689+
# Apple
690+
_reset_simulator_on_error(device, type)
691+
_run_with_retry(args, shell, check, timeout, retry_time-1, device, type)
692+
else:
693+
subprocess.run(args, shell=shell, check=check, timeout=timeout)
694+
695+
674696
if __name__ == '__main__':
675697
flags.mark_flag_as_required("testapp_dir")
676698
app.run(main)

0 commit comments

Comments
 (0)