diff --git a/.github/scripts/run-ui-tests.sh b/.github/scripts/run-ui-tests.sh index 9a49ac52de..310e8154e5 100644 --- a/.github/scripts/run-ui-tests.sh +++ b/.github/scripts/run-ui-tests.sh @@ -2,6 +2,35 @@ set -euo pipefail +# The emulator runner waits until the emulator's output closes. Processes that outlive the emulator +# (its crashpad_handler, the Gradle daemon, the adb server) can keep it open and hold the job until +# its timeout after the tests already finished. Stop them here, with bounded waits, so the test +# result decides the step. Only on GitHub Actions: the kills are host-wide, and a local run may share +# the host with other emulators. +EMULATOR_EXIT_TIMEOUT_SECONDS=30 + +stop_emulator() { + ./gradlew --stop > /dev/null 2>&1 || true + adb emu kill > /dev/null 2>&1 || true + local exited=false + for _ in $(seq "$EMULATOR_EXIT_TIMEOUT_SECONDS"); do + if ! pgrep -f qemu-system > /dev/null; then + exited=true + break + fi + sleep 1 + done + if [[ "$exited" != true ]]; then + echo "::warning::Emulator did not exit ${EMULATOR_EXIT_TIMEOUT_SECONDS}s after emu kill; killing it." + pkill -9 -f qemu-system || true + fi + pkill -9 -f crashpad_handler || true + adb kill-server > /dev/null 2>&1 || true +} +if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then + trap stop_emulator EXIT +fi + adb wait-for-device echo "Waiting for boot to complete..." adb shell 'while [ -z "$(getprop sys.boot_completed)" ]; do sleep 1; done'