@@ -419,6 +419,20 @@ def _delete_simulator(device_id):
419
419
subprocess .run (args = args , check = True )
420
420
421
421
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
+
422
436
def _get_bundle_id (app_path , config ):
423
437
"""Get app bundle id from build_testapps.json file."""
424
438
for api in config ["apis" ]:
@@ -446,14 +460,14 @@ def _install_apple_app(app_path, device_id):
446
460
"""Install integration_test app into the simulator."""
447
461
args = ["xcrun" , "simctl" , "install" , device_id , app_path ]
448
462
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 )
450
464
451
465
452
466
def _uninstall_apple_app (bundle_id , device_id ):
453
467
"""Uninstall integration_test app from the simulator."""
454
468
args = ["xcrun" , "simctl" , "uninstall" , device_id , bundle_id ]
455
469
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 )
457
471
458
472
459
473
def _get_apple_test_log (bundle_id , app_path , device_id ):
@@ -562,17 +576,6 @@ def _create_and_boot_emulator(sdk_id):
562
576
else :
563
577
time .sleep (45 )
564
578
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
-
576
579
577
580
def _reset_emulator_on_error (type = _RESET_TYPE_REBOOT ):
578
581
if type == _RESET_TYPE_WIPE_REBOOT :
@@ -671,6 +674,25 @@ def _get_android_test_log(test_package):
671
674
return result .stdout
672
675
673
676
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
+
674
696
if __name__ == '__main__' :
675
697
flags .mark_flag_as_required ("testapp_dir" )
676
698
app .run (main )
0 commit comments