Skip to content

Commit 3cdec73

Browse files
ales-drnzclaude
andcommitted
CI: iOS device job with a watchdog for flutter/flutter#181771
flutter test can miss the app's VM service on an iOS simulator and wait forever after the build. The script stops an attempt when no test has started three minutes after the build and retries, up to three attempts; a run that starts and fails still fails the job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e30bc0f commit 3cdec73

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Runs test_app/integration_test on the iOS simulator $1, with a watchdog.
3+
#
4+
# flutter test sometimes misses the app's VM service URL on an iOS
5+
# simulator and then waits forever after the build
6+
# (https://github.com/flutter/flutter/issues/181771, fix pending in
7+
# https://github.com/flutter/flutter/pull/193142). When no test has started
8+
# GRACE seconds after the build, the attempt is stopped and retried, up to
9+
# 3 attempts. A run that starts and fails still fails the job.
10+
#
11+
# Run from test_app/.
12+
set -uo pipefail
13+
14+
udid=$1
15+
grace=${GRACE:-180}
16+
app=com.alesdrnz.dartSmb2TestApp
17+
18+
attempt() {
19+
local log pid built=""
20+
log=$(mktemp)
21+
(flutter test integration_test -d "$udid" 2>&1 | tee "$log") &
22+
pid=$!
23+
while kill -0 "$pid" 2>/dev/null; do
24+
if [ -z "$built" ] && grep -q "Xcode build done" "$log"; then built=$(date +%s); fi
25+
# Test progress lines look like "00:01 +3: offline ...", after "+0: loading ...".
26+
if [ -n "$built" ] && ! grep -E ' \+[0-9]+( ~[0-9]+)?( -[0-9]+)?: ' "$log" | grep -vq ': loading ' &&
27+
[ $(($(date +%s) - built)) -gt "$grace" ]; then
28+
echo "::warning::No test started ${grace}s after the build (flutter/flutter#181771): retrying."
29+
pkill -f "flutter_tools.snapshot test" || true
30+
pkill -P "$pid" || true
31+
wait "$pid"
32+
xcrun simctl terminate "$udid" "$app" 2>/dev/null || true
33+
return 2
34+
fi
35+
sleep 5
36+
done
37+
wait "$pid"
38+
}
39+
40+
for n in 1 2 3; do
41+
echo "::group::Integration tests, attempt $n"
42+
attempt
43+
status=$?
44+
echo "::endgroup::"
45+
[ "$status" -ne 2 ] && exit "$status"
46+
done
47+
echo "::error::The integration tests never started in 3 attempts."
48+
exit 1

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,15 @@ jobs:
235235
- name: Integration tests (iOS simulator)
236236
if: matrix.name == 'iOS'
237237
working-directory: test_app
238-
timeout-minutes: 20
239-
# flutter drive with test_driver/, as in mpv_audio_kit: flutter test
240-
# can wait forever for the app's VM service on a CI simulator.
238+
timeout-minutes: 30
239+
# A watchdog retries when flutter test misses the app on the
240+
# simulator (flutter/flutter#181771); see the script.
241241
run: |
242242
udid="$(xcrun simctl list devices available -j | python3 -c 'import json,sys; d=json.load(sys.stdin)["devices"]; print(next(x["udid"] for r,v in d.items() if "iOS" in r for x in v if x["name"].startswith("iPhone")))')"
243243
echo "UDID=$udid" >> "$GITHUB_ENV"
244244
xcrun simctl boot "$udid"
245245
xcrun simctl bootstatus "$udid" -b
246-
flutter drive --driver test_driver/integration_test.dart \
247-
--target integration_test/smoke_test.dart -d "$udid"
246+
bash ../.github/scripts/ios_integration_tests.sh "$udid"
248247
- name: Simulator log
249248
if: failure() && matrix.name == 'iOS'
250249
run: xcrun simctl spawn "$UDID" log show --last 15m --style compact --predicate 'process == "Runner"' | tail -200

0 commit comments

Comments
 (0)