Skip to content

Commit 3ddd997

Browse files
authored
Reboot Android Emulator on test errors
1 parent 984f698 commit 3ddd997

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

.github/workflows/integration_tests.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ jobs:
750750
shell: bash
751751
run: |
752752
if [ ! -f testapps/test-results-desktop-${{ matrix.os }}-${{ matrix.ssl_variant }}.log.json ]; then
753-
echo "__SUMMARY_MISSING__" > testapps/test-results-desktop-${{ matrix.os }}-${{ matrix.ssl_variant }}.log.json
753+
mkdir -p testapps && echo "__SUMMARY_MISSING__" > testapps/test-results-desktop-${{ matrix.os }}-${{ matrix.ssl_variant }}.log.json
754754
fi
755755
- name: Upload Desktop test results artifact
756756
if: ${{ !cancelled() }}
@@ -836,7 +836,7 @@ jobs:
836836
shell: bash
837837
run: |
838838
if [ ! -f "testapps/test-results-android-${{ matrix.build_os }}-${{ matrix.android_device }}.log.json" ]; then
839-
echo "__SUMMARY_MISSING__" > "testapps/test-results-android-${{ matrix.build_os }}-${{ matrix.android_device }}.log.json"
839+
mkdir -p testapps && echo "__SUMMARY_MISSING__" > "testapps/test-results-android-${{ matrix.build_os }}-${{ matrix.android_device }}.log.json"
840840
fi
841841
- name: Upload Android test results artifact
842842
if: ${{ !cancelled() }}
@@ -921,7 +921,7 @@ jobs:
921921
shell: bash
922922
run: |
923923
if [ ! -f "testapps/test-results-ios-macos-latest-${{ matrix.ios_device }}.log.json" ]; then
924-
echo "__SUMMARY_MISSING__" > "testapps/test-results-ios-macos-latest-${{ matrix.ios_device }}.log.json"
924+
mkdir -p testapps && echo "__SUMMARY_MISSING__" > "testapps/test-results-ios-macos-latest-${{ matrix.ios_device }}.log.json"
925925
fi
926926
- name: Upload iOS test results artifact
927927
if: ${{ !cancelled() }}
@@ -990,7 +990,7 @@ jobs:
990990
shell: bash
991991
run: |
992992
if [ ! -f "testapps/test-results-tvos-macos-latest-${{ matrix.tvos_device }}.log.json" ]; then
993-
echo "__SUMMARY_MISSING__" > "testapps/test-results-tvos-macos-latest-${{ matrix.tvos_device }}.log.json"
993+
mkdir -p testapps && echo "__SUMMARY_MISSING__" > "testapps/test-results-tvos-macos-latest-${{ matrix.tvos_device }}.log.json"
994994
fi
995995
- name: Upload tvOS test results artifact
996996
if: ${{ !cancelled() }}

scripts/gha/it_workflow.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
_COMMENT_TITLE_FAIL = "### ❌  Integration test FAILED\n"
6363
_COMMENT_TITLE_SUCCEED = "### ✅  Integration test succeeded!\n"
6464

65-
_COMMENT_FLAKY_TRACKER = "\nAdd flaky tests to **[go/fpl-cpp-flake-tracker](http://go/fpl-cpp-flake-tracker)**\n"
65+
_COMMENT_FLAKY_TRACKER = "\n\nAdd flaky tests to **[go/fpl-cpp-flake-tracker](http://go/fpl-cpp-flake-tracker)**\n"
6666

6767
_COMMENT_IDENTIFIER = "integration-test-status-comment"
6868
_COMMENT_SUFFIX = f'\n\n\n<hidden value="{_COMMENT_IDENTIFIER}"></hidden>'
@@ -130,6 +130,7 @@ def test_progress(token, issue_number, actor, commit, run_id):
130130
comment = (_COMMENT_TITLE_PROGESS_FAIL +
131131
_get_description(actor, commit, run_id) +
132132
log_summary +
133+
_COMMENT_FLAKY_TRACKER +
133134
_COMMENT_SUFFIX)
134135
_update_comment(token, issue_number, comment)
135136

@@ -150,6 +151,7 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
150151
comment = (_COMMENT_TITLE_FAIL +
151152
_get_description(actor, commit, run_id) +
152153
log_summary +
154+
_COMMENT_FLAKY_TRACKER +
153155
_COMMENT_SUFFIX)
154156
_update_comment(token, issue_number, comment)
155157

scripts/gha/test_lab.py

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def run(self):
278278
self.raw_result_link = raw_result_link.group(1)
279279

280280
self.logs = self._get_testapp_log_text_from_gcs()
281+
logging.info("Test result: %s", self.logs)
281282

282283
@property
283284
def _gcloud_command(self):

scripts/gha/test_simulator.py

+42-21
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ def _get_apple_test_log(bundle_id, app_path, device_id):
461461
return None
462462

463463
log_path = os.path.join(result.stdout.strip(), "Documents", "GameLoopResults", _RESULT_FILE)
464-
return _read_file(log_path)
464+
log = _read_file(log_path)
465+
logging.info("Apple test result: %s", log)
466+
return log
465467

466468

467469
def _read_file(path):
@@ -501,12 +503,9 @@ def _setup_android(platform_version, build_tool_version, sdk_id):
501503
logging.info("Install packages: %s", " ".join(args))
502504
subprocess.run(args=args, check=True)
503505

504-
args = ["sdkmanager", "--licenses"]
505-
logging.info("Accept all licenses: %s", " ".join(args))
506-
p_yes = subprocess.Popen(["echo", "yes"], stdout=subprocess.PIPE)
507-
proc = subprocess.Popen(args, stdin=p_yes.stdout, stdout=subprocess.PIPE)
508-
p_yes.stdout.close()
509-
proc.communicate()
506+
command = "yes | sdkmanager --licenses"
507+
logging.info("Accept all licenses: %s", command)
508+
subprocess.run(command, shell=True, check=False)
510509

511510
args = ["sdkmanager", sdk_id]
512511
logging.info("Download an emulator: %s", " ".join(args))
@@ -521,25 +520,24 @@ def _shutdown_emulator():
521520
command = "adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done"
522521
logging.info("Kill all running emulator: %s", command)
523522
subprocess.Popen(command, universal_newlines=True, shell=True, stdout=subprocess.PIPE)
523+
time.sleep(5)
524+
args = ["adb", "kill-server"]
525+
logging.info("Kill adb server: %s", " ".join(args))
526+
subprocess.run(args=args, check=False)
527+
time.sleep(5)
528+
524529

525530
def _create_and_boot_emulator(sdk_id):
526-
args = ["avdmanager", "-s",
527-
"create", "avd",
528-
"-n", "test_emulator",
529-
"-k", sdk_id,
530-
"-f"]
531-
logging.info("Create an emulator: %s", " ".join(args))
532-
p_no = subprocess.Popen(["echo", "no"], stdout=subprocess.PIPE)
533-
proc = subprocess.Popen(args, stdin=p_no.stdout, stdout=subprocess.PIPE)
534-
p_no.stdout.close()
535-
proc.communicate()
531+
_shutdown_emulator()
532+
533+
command = "echo no | avdmanager -s create avd -n test_emulator -k '%s' -f" % sdk_id
534+
logging.info("Create an emulator: %s", command)
535+
subprocess.run(command, shell=True, check=True)
536536

537537
args = ["adb", "start-server"]
538538
logging.info("Start adb server: %s", " ".join(args))
539539
subprocess.run(args=args, check=True)
540540

541-
_shutdown_emulator()
542-
543541
if not FLAGS.ci:
544542
command = "$ANDROID_HOME/emulator/emulator -avd test_emulator &"
545543
else:
@@ -550,14 +548,30 @@ def _create_and_boot_emulator(sdk_id):
550548
args = ["adb", "wait-for-device"]
551549
logging.info("Wait for emulator to boot: %s", " ".join(args))
552550
subprocess.run(args=args, check=True)
553-
554551
if FLAGS.ci:
555552
# wait extra 90 seconds to ensure emulator booted.
556553
time.sleep(90)
557554
else:
558555
time.sleep(45)
559556

560557

558+
def _reset_emulator_on_error(instrumented_test_result):
559+
logging.info("game-loop test result: %s", instrumented_test_result)
560+
if "FAILURES!!!" in instrumented_test_result:
561+
logging.info("game-loop test error!!! reboot emualtor...")
562+
args = ["adb", "-e", "reboot"]
563+
logging.info("Reboot android emulator: %s", " ".join(args))
564+
subprocess.run(args=args, check=True)
565+
args = ["adb", "wait-for-device"]
566+
logging.info("Wait for emulator to boot: %s", " ".join(args))
567+
subprocess.run(args=args, check=True)
568+
if FLAGS.ci:
569+
# wait extra 90 seconds to ensure emulator booted.
570+
time.sleep(90)
571+
else:
572+
time.sleep(45)
573+
574+
561575
def _get_package_name(app_path):
562576
command = "aapt dump badging %s | awk -v FS=\"'\" '/package: name=/{print $2}'" % app_path
563577
logging.info("Get package_name: %s", command)
@@ -597,6 +611,11 @@ def _uninstall_android_app(package_name):
597611

598612
def _install_android_gameloop_app(gameloop_project):
599613
os.chdir(gameloop_project)
614+
logging.info("CD to gameloop_project: %s", gameloop_project)
615+
_uninstall_android_app("com.google.firebase.gameloop")
616+
args = ["./gradlew", "clean"]
617+
logging.info("Clean game-loop cache: %s", " ".join(args))
618+
subprocess.run(args=args, check=False)
600619
args = ["./gradlew", "installDebug", "installDebugAndroidTest"]
601620
logging.info("Installing game-loop app and test: %s", " ".join(args))
602621
subprocess.run(args=args, check=True)
@@ -609,7 +628,8 @@ def _run_instrumented_test():
609628
args = ["adb", "shell", "am", "instrument",
610629
"-w", "%s.test/androidx.test.runner.AndroidJUnitRunner" % _GAMELOOP_PACKAGE]
611630
logging.info("Running game-loop test: %s", " ".join(args))
612-
subprocess.run(args=args, check=False)
631+
result = subprocess.run(args=args, capture_output=True, text=True, check=False)
632+
_reset_emulator_on_error(result.stdout)
613633

614634

615635
def _get_android_test_log(test_package):
@@ -619,6 +639,7 @@ def _get_android_test_log(test_package):
619639
args = ["adb", "shell", "su", "0", "cat", path]
620640
logging.info("Get android test result: %s", " ".join(args))
621641
result = subprocess.run(args=args, capture_output=True, text=True, check=False)
642+
logging.info("Android test result: %s", result.stdout)
622643
return result.stdout
623644

624645

0 commit comments

Comments
 (0)