Skip to content

Commit

Permalink
Make avd_test less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Oct 24, 2023
1 parent 985454a commit d2f2a9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest, macos-13]
steps:
- name: Check out
uses: actions/checkout@v3
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:

test:
name: Test on ${{ matrix.api }}
runs-on: macos-latest
runs-on: macos-13
needs: build
strategy:
fail-fast: false
Expand All @@ -111,12 +111,6 @@ jobs:
with:
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"

- name: Set up Python 3
uses: actions/setup-python@v4
with:
Expand Down
22 changes: 16 additions & 6 deletions scripts/avd_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,24 @@ wait_emu() {
timeout $boot_timeout bash -c $wait_fn &
local wait_pid=$!

# Handle the case when emulator dies earlier than wait
# Handle the case when emulator dies earlier than timeout
wait -p which_pid -n $emu_pid $wait_pid
[ $which_pid -eq $wait_pid ]
}

run_content_cmd() {
while true; do
local out=$(adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method $1'" \| /system/xbin/su | tee /dev/fd/2)
if ! grep -q 'Bundle\[' <<< "$out"; then
# The call failed, wait a while and retry later
sleep 30
else
grep -q 'result=true' <<< "$out"
return $?
fi
done
}

test_emu() {
local variant=$1

Expand All @@ -110,17 +123,14 @@ test_emu() {

# Install the Magisk app
adb install -r -g out/app-${variant}.apk
adb shell appops set com.topjohnwu.magisk REQUEST_INSTALL_PACKAGES allow

# Use the app to run setup and reboot
adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method setup'" \| /system/xbin/su \
| tee /dev/fd/2 | grep -q 'result=true'
run_content_cmd setup
adb reboot
wait_emu wait_for_boot

# Run app tests
adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method test'" \| /system/xbin/su \
| tee /dev/fd/2 | grep -q 'result=true'
run_content_cmd test
adb shell echo "'su -c id'" \| /system/xbin/su 2000 | tee /dev/fd/2 | grep -q 'uid=0'
}

Expand Down

0 comments on commit d2f2a9e

Please sign in to comment.