Retry a failed screenshot block

This commit is contained in:
Roland Geider
2026-08-26 15:13:06 +02:00
parent f518452cb2
commit 24b2d91757
3 changed files with 57 additions and 13 deletions

View File

@@ -5,14 +5,51 @@
set -euo pipefail
blocks=5
attempts=3
block_timeout=10m
# Homebrew installs coreutils under the g-prefixed names only
timeout=$(command -v timeout || command -v gtimeout) || {
echo "Found neither timeout nor gtimeout, install coreutils"
exit 1
}
device_type=${1:?Usage: take-screenshots.sh <device type> [flutter drive args]}
shift
for block in 1 2 3 4 5; do
flutter drive \
--driver=test_driver/screenshot_driver.dart \
--target=integration_test/make_screenshots_test.dart \
--dart-define=DEVICE_TYPE="$device_type" \
--dart-define=LANGUAGES="$block/5" \
"$@"
# flutter drive gives up within seconds on an offline device, so wait for it
# to come back instead of burning the next attempt on it
wait_for_device() {
adb devices | tail -n +2 | grep -q . || return 0
adb reconnect offline || true
"$timeout" 120s adb wait-for-device shell \
'while [ "$(getprop sys.boot_completed)" != 1 ]; do sleep 2; done' || true
}
for block in $(seq "$blocks"); do
for attempt in $(seq "$attempts"); do
status=0
# Both the Xcode build and the driver's connect retry forever on their own.
# timeout signals the whole process group, so no dart child survives.
"$timeout" --kill-after=30s "$block_timeout" flutter drive \
--driver=test_driver/screenshot_driver.dart \
--target=integration_test/make_screenshots_test.dart \
--dart-define=DEVICE_TYPE="$device_type" \
--dart-define=LANGUAGES="$block/$blocks" \
"$@" || status=$?
if [ "$status" -eq 0 ]; then
break
fi
if [ "$attempt" -eq "$attempts" ]; then
echo "Block $block still fails after $attempts attempts, giving up"
exit 1
fi
# Usually the device went offline while handing the images over
echo "Block $block failed with $status, attempt $((attempt + 1)) of $attempts"
wait_for_device
done
done

View File

@@ -14,9 +14,8 @@ jobs:
screenshots_apple:
name: 'Apple - ${{ matrix.device.name }}'
runs-on: macos-latest
# A run takes about 20 minutes. When flutter drive cannot reach the app's
# VM service it retries forever
timeout-minutes: 40
# A clean run takes about 30 minutes, the script may retry a block twice
timeout-minutes: 75
strategy:
# The jobs write into separate folders and a flaky one should not take
# the healthy ones down with it
@@ -56,6 +55,10 @@ jobs:
open -a Simulator || true
n=0; until xcrun simctl bootstatus "$SIMULATOR" -b || [ $n -ge 60 ]; do sleep 1; n=$((n+1)); done
# The image ships no GNU coreutils, take-screenshots.sh needs gtimeout
- name: Install coreutils
run: brew install coreutils
- name: Generate screenshots
run: .github/scripts/take-screenshots.sh ${{ matrix.device.device_type }} -d "$SIMULATOR"
@@ -68,7 +71,8 @@ jobs:
screenshots_android:
name: 'Android - ${{ matrix.device.name }}'
runs-on: ubuntu-latest
timeout-minutes: 40
# A clean run takes about 25 minutes, the script may retry a block twice
timeout-minutes: 60
strategy:
# The jobs write into separate folders and a flaky one should not take
# the healthy ones down with it

View File

@@ -57,8 +57,11 @@ so the setup above is only needed locally.
## Troubleshooting
If a run ends with `DriverError: ... Service has disappeared` and writes no
images, it lost the app before it could collect them. Fewer languages per run
makes that less likely, otherwise just run it again.
images, it lost the app before it could collect them. The tests themselves
usually passed, only the hand-over failed, so running that block again is
enough. A block that instead keeps printing `It is taking an unusually long
time to connect to the VM` never gives up on its own, kill it. In CI the script
puts every block on a ten minute leash and retries it up to three times.
See also