Skip to content

Commit 1ae1aa1

Browse files
fix: driver retries
1 parent dfd833d commit 1ae1aa1

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

.maestro/scripts/run-tests.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ set_font_scale default
143143
# maestro-runner exits non-zero when the tag filter matches zero flows. That's
144144
# not a real failure for us (e.g. running a single flow that has no
145145
# accessibility variant), and letting it propagate aborts later test suites.
146+
is_ci_android() {
147+
[ "$PLATFORM" = android ] && { [ -n "${CI:-}" ] || [ -n "${GITHUB_ACTIONS:-}" ]; }
148+
}
149+
146150
is_driver_startup_crash() {
147151
grep -Eqi 'failed to create driver|driver crashed on startup|DeviceLab driver crashed' "$1"
148152
}
@@ -152,20 +156,20 @@ cleanup_devicelab_driver() {
152156
local sock="/tmp/devicelab-driver-${DEVICE_ID}.sock"
153157
adb -s "$DEVICE_ID" forward --remove "localfilesystem:$sock" 2>/dev/null || true
154158
adb -s "$DEVICE_ID" shell am force-stop dev.devicelab.driver.android.test 2>/dev/null || true
155-
sleep 3
159+
sleep 8
156160
}
157161

158162
run_maestro() {
159-
local max_attempts rc tmp attempt=1
163+
local max_attempts rc tmp attempt=1 delayed_retry=0
160164
if [ -n "${MAESTRO_MAX_RETRIES:-}" ]; then
161165
max_attempts="$MAESTRO_MAX_RETRIES"
162-
elif [ -n "${CI:-}" ] && [ "$PLATFORM" = android ]; then
166+
elif is_ci_android; then
163167
max_attempts=3 # 1 initial run + 2 retries
164168
else
165169
max_attempts=1
166170
fi
167171

168-
while [ "$attempt" -le "$max_attempts" ]; do
172+
while true; do
169173
tmp=$(mktemp)
170174
# `script` allocates a pseudo-TTY so the runner keeps
171175
# ANSI colors when piped through `tee`.
@@ -192,12 +196,22 @@ run_maestro() {
192196
return 0
193197
fi
194198

195-
if [ "$attempt" -lt "$max_attempts" ] && is_driver_startup_crash "$tmp"; then
196-
echo "warn: driver crashed on startup (attempt $attempt/$max_attempts), retrying..." >&2
197-
cleanup_devicelab_driver
198-
attempt=$((attempt + 1))
199-
rm -f "$tmp"
200-
continue
199+
if is_driver_startup_crash "$tmp"; then
200+
if [ "$attempt" -lt "$max_attempts" ]; then
201+
echo "warn: driver crashed on startup (attempt $attempt/$max_attempts), retrying..." >&2
202+
cleanup_devicelab_driver
203+
attempt=$((attempt + 1))
204+
rm -f "$tmp"
205+
continue
206+
fi
207+
if [ "$delayed_retry" -eq 0 ] && is_ci_android; then
208+
echo "warn: driver still failing, waiting before delayed retry..." >&2
209+
delayed_retry=1
210+
cleanup_devicelab_driver
211+
sleep 10
212+
rm -f "$tmp"
213+
continue
214+
fi
201215
fi
202216

203217
rm -f "$tmp"

0 commit comments

Comments
 (0)