Skip to content

Commit c1841bb

Browse files
authored
Add retry to iOS/tvOS/Android test on virtual device
1 parent f5022dc commit c1841bb

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

scripts/gha/integration_testing/gameloop_android/app/src/androidTest/java/com/google/firebase/gameloop/GameLoopUITest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.junit.runner.RunWith
1919
class GameLoopUITest {
2020

2121
companion object {
22-
const val GAMELOOP_TIMEOUT = 15 * 60 * 1000L
22+
const val GAMELOOP_TIMEOUT = 10 * 60 * 1000L
2323
}
2424

2525
private lateinit var device: UiDevice

scripts/gha/test_simulator.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191

9292
_GAMELOOP_PACKAGE = "com.google.firebase.gameloop"
9393
_RESULT_FILE = "Results1.json"
94+
_TEST_RETRY = 3
9495

9596
FLAGS = flags.FLAGS
9697

@@ -208,9 +209,8 @@ def main(argv):
208209

209210
for app_path in ios_testapps:
210211
bundle_id = _get_bundle_id(app_path, config)
211-
tests.append(Test(
212-
testapp_path=app_path,
213-
logs=_run_apple_gameloop_test(bundle_id, app_path, ios_gameloop_app, device_id)))
212+
logs=_run_apple_gameloop_test(bundle_id, app_path, ios_gameloop_app, device_id, _TEST_RETRY)
213+
tests.append(Test(testapp_path=app_path, logs=logs))
214214

215215
_shutdown_simulator()
216216

@@ -249,9 +249,8 @@ def main(argv):
249249

250250
for app_path in tvos_testapps:
251251
bundle_id = _get_bundle_id(app_path, config)
252-
tests.append(Test(
253-
testapp_path=app_path,
254-
logs=_run_apple_gameloop_test(bundle_id, app_path, tvos_gameloop_app, device_id)))
252+
logs=_run_apple_gameloop_test(bundle_id, app_path, tvos_gameloop_app, device_id, _TEST_RETRY)
253+
tests.append(Test(testapp_path=app_path, logs=logs))
255254

256255
_shutdown_simulator()
257256

@@ -285,9 +284,8 @@ def main(argv):
285284

286285
for app_path in android_testapps:
287286
package_name = _get_package_name(app_path)
288-
tests.append(Test(
289-
testapp_path=app_path,
290-
logs=_run_android_gameloop_test(package_name, app_path, android_gameloop_project)))
287+
logs=_run_android_gameloop_test(package_name, app_path, android_gameloop_project, _TEST_RETRY)
288+
tests.append(Test(testapp_path=app_path, logs=logs))
291289

292290
_shutdown_emulator()
293291

@@ -420,13 +418,19 @@ def _get_bundle_id(app_path, config):
420418
return api["bundle_id"]
421419

422420

423-
def _run_apple_gameloop_test(bundle_id, app_path, gameloop_app, device_id):
421+
def _run_apple_gameloop_test(bundle_id, app_path, gameloop_app, device_id, retry=1):
424422
"""Run gameloop test and collect test result."""
425423
logging.info("Running apple gameloop test: %s, %s, %s, %s", bundle_id, app_path, gameloop_app, device_id)
426424
_install_apple_app(app_path, device_id)
427425
_run_xctest(gameloop_app, device_id)
428426
logs = _get_apple_test_log(bundle_id, app_path, device_id)
429427
_uninstall_apple_app(bundle_id, device_id)
428+
if retry > 1:
429+
results = test_validation.validate_results_cpp(logs)
430+
if not results.complete:
431+
logging.info("Retry _run_apple_gameloop_test. Remaining retry: %s", retry-1)
432+
return _run_apple_gameloop_test(bundle_id, app_path, gameloop_app, device_id, retry=retry-1)
433+
430434
return logs
431435

432436

@@ -462,14 +466,13 @@ def _get_apple_test_log(bundle_id, app_path, device_id):
462466

463467
def _read_file(path):
464468
"""Extracts the contents of a file."""
465-
with open(path, "r") as f:
466-
test_result = f.read()
467-
468-
logging.info("Reading file: %s", path)
469-
logging.info("File contant: %s", test_result)
470-
return test_result
471-
469+
if os.path.isfile(path):
470+
with open(path, "r") as f:
471+
test_result = f.read()
472472

473+
logging.info("Reading file: %s", path)
474+
logging.info("File content: %s", test_result)
475+
return test_result
473476

474477

475478
# -------------------Android Only-------------------
@@ -556,12 +559,18 @@ def _get_package_name(app_path):
556559
return package_name
557560

558561

559-
def _run_android_gameloop_test(package_name, app_path, gameloop_project):
562+
def _run_android_gameloop_test(package_name, app_path, gameloop_project, retry=1):
560563
logging.info("Running android gameloop test: %s, %s, %s", package_name, app_path, gameloop_project)
561564
_install_android_app(app_path)
562565
_run_instrumented_test()
563566
logs = _get_android_test_log(package_name)
564567
_uninstall_android_app(package_name)
568+
if retry > 1:
569+
results = test_validation.validate_results_cpp(logs)
570+
if not results.complete:
571+
logging.info("Retry _run_android_gameloop_test. Remaining retry: %s", retry-1)
572+
return _run_android_gameloop_test(package_name, app_path, gameloop_project, retry=retry-1)
573+
565574
return logs
566575

567576

0 commit comments

Comments
 (0)