Skip to content

Commit 670fc60

Browse files
authored
Add logic to retry playmode tests (#857)
* Add logic to retry playmode tests on failures * Update build_testapps.py * Update build_testapps.py
1 parent 509e63e commit 670fc60

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/gha/build_testapps.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def main(argv):
338338
if p == _DESKTOP: # e.g. 'Desktop' -> 'OSXUniversal'
339339
p = get_desktop_platform()
340340
if p == _PLAYMODE:
341-
logs = perform_in_editor_tests(dir_helper)
341+
logs = perform_in_editor_tests(dir_helper, remaining_retries=2)
342342
playmode_tests.append(Test(testapp_path=dir_helper.unity_project_dir, logs=logs))
343343
else:
344344
build_testapp(
@@ -580,7 +580,7 @@ def patch_android_env(unity_version):
580580
os.environ["UNITY_ANDROID_JDK"]=os.environ["JAVA_HOME"]
581581

582582

583-
def perform_in_editor_tests(dir_helper, retry_on_license_check=True):
583+
def perform_in_editor_tests(dir_helper, retry_on_license_check=True, remaining_retries=0):
584584
"""Executes the testapp within the Unity Editor's play mode.
585585
586586
Unity has a feature to run a project within the editor itself,
@@ -596,6 +596,8 @@ def perform_in_editor_tests(dir_helper, retry_on_license_check=True):
596596
the logs, restart the tests. This is because a license check will cause
597597
a reload of assemblies, which can mess with the tests. The second run
598598
will not retry if this happens again (which doesn't normally happen).
599+
remaining_retries: Number of remaining retries allowed before the test is
600+
considered to have failed.
599601
600602
Raises:
601603
RuntimeError: This error will be thrown if any of the following conditions
@@ -629,7 +631,9 @@ def perform_in_editor_tests(dir_helper, retry_on_license_check=True):
629631
if retry_on_license_check and "License updated successfully" in text:
630632
logging.info("License check caused assembly reload. Retrying tests.")
631633
open_process.kill()
632-
perform_in_editor_tests(dir_helper, retry_on_license_check=False)
634+
# Don't count this against the remaining_retries amount, since the test didn't fail
635+
perform_in_editor_tests(dir_helper, retry_on_license_check=False,
636+
remaining_retries=remaining_retries)
633637
return
634638
open_process.kill()
635639
logging.info("Finished running playmode tests")
@@ -639,8 +643,18 @@ def perform_in_editor_tests(dir_helper, retry_on_license_check=True):
639643
if results.passes and not results.fails: # Success
640644
logging.info(results.summary)
641645
else: # Failed
646+
if remaining_retries > 0:
647+
logging.info("Test failed, but will retry %d more times" % remaining_retries)
648+
perform_in_editor_tests(dir_helper, retry_on_license_check=retry_on_license_check,
649+
remaining_retries=remaining_retries-1)
650+
return
642651
raise RuntimeError(results.summary)
643652
else: # Generally caused by timeout or crash
653+
if remaining_retries > 0:
654+
logging.info("Test timed out or crashed, but will retry %d more times" % remaining_retries)
655+
perform_in_editor_tests(dir_helper, retry_on_license_check=retry_on_license_check,
656+
remaining_retries=remaining_retries-1)
657+
return
644658
raise RuntimeError(
645659
"Tests did not finish running. Log tail:\n" + results.summary)
646660

0 commit comments

Comments
 (0)