Skip to content

Commit 304d1c9

Browse files
abueideclaude
andcommitted
refactor: centralize detach logic with --wait-ready flag
Add --wait-ready flag to android.sh emulator start and ios.sh simulator start: - Waits for device to be ready (health check passes) - Exits 0 and detaches (device stays running as daemon) - Used in dev mode for iteration YAML files now just call: - Pure mode: `android.sh emulator start --pure $device` + tail -f - Dev mode: `android.sh emulator start --wait-ready $device` This centralizes the detach logic and eliminates repetitive code in test suites. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 63e22f8 commit 304d1c9

5 files changed

Lines changed: 51 additions & 61 deletions

File tree

examples/react-native/tests/test-suite-all-e2e.yaml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,7 @@ processes:
7777
# Dev mode: start, wait for ready, then detach
7878
echo "Starting Android emulator: $device"
7979
unset ANDROID_EMULATOR_FOREGROUND
80-
android.sh emulator start "$device"
81-
82-
echo "Waiting for emulator to be ready..."
83-
max_wait=120
84-
elapsed=0
85-
while ! android.sh emulator ready; do
86-
sleep 3
87-
elapsed=$((elapsed + 3))
88-
if [ $elapsed -ge $max_wait ]; then
89-
echo "ERROR: Emulator did not become ready within ${max_wait}s" >&2
90-
exit 1
91-
fi
92-
done
93-
echo "✓ Emulator ready and running in background (dev mode)"
94-
exit 0
80+
android.sh emulator start --wait-ready "$device"
9581
fi
9682
availability:
9783
restart: "no"
@@ -114,21 +100,7 @@ processes:
114100
tail -f /dev/null
115101
else
116102
# Dev mode: start, wait for ready, then detach
117-
ios.sh simulator start ${IOS_DEVICE}
118-
119-
echo "Waiting for simulator to be ready..."
120-
max_wait=60
121-
elapsed=0
122-
while ! ios.sh simulator ready; do
123-
sleep 2
124-
elapsed=$((elapsed + 2))
125-
if [ $elapsed -ge $max_wait ]; then
126-
echo "ERROR: Simulator did not become ready within ${max_wait}s" >&2
127-
exit 1
128-
fi
129-
done
130-
echo "✓ Simulator ready and running in background (dev mode)"
131-
exit 0
103+
ios.sh simulator start --wait-ready ${IOS_DEVICE}
132104
fi
133105
depends_on:
134106
sync-simulators:

examples/react-native/tests/test-suite-android-e2e.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,7 @@ processes:
5656
# Dev mode: start emulator, wait for ready, then detach
5757
echo "Starting Android emulator: $device"
5858
unset ANDROID_EMULATOR_FOREGROUND
59-
android.sh emulator start "$device"
60-
61-
echo "Waiting for emulator to be ready..."
62-
max_wait=120
63-
elapsed=0
64-
while ! android.sh emulator ready; do
65-
sleep 3
66-
elapsed=$((elapsed + 3))
67-
if [ $elapsed -ge $max_wait ]; then
68-
echo "ERROR: Emulator did not become ready within ${max_wait}s" >&2
69-
exit 1
70-
fi
71-
done
72-
echo "✓ Emulator ready and running in background (dev mode)"
73-
exit 0
59+
android.sh emulator start --wait-ready "$device"
7460
fi
7561
availability:
7662
restart: "no"

examples/react-native/tests/test-suite-ios-e2e.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,7 @@ processes:
4848
tail -f /dev/null # Keep alive
4949
else
5050
# Dev mode: start simulator, wait for ready, then detach
51-
ios.sh simulator start ${IOS_DEVICE}
52-
53-
echo "Waiting for simulator to be ready..."
54-
max_wait=60
55-
elapsed=0
56-
while ! ios.sh simulator ready; do
57-
sleep 2
58-
elapsed=$((elapsed + 2))
59-
if [ $elapsed -ge $max_wait ]; then
60-
echo "ERROR: Simulator did not become ready within ${max_wait}s" >&2
61-
exit 1
62-
fi
63-
done
64-
echo "✓ Simulator ready and running in background (dev mode)"
65-
exit 0
51+
ios.sh simulator start --wait-ready ${IOS_DEVICE}
6652
fi
6753
depends_on:
6854
sync-simulators:

plugins/android/virtenv/scripts/user/android.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ case "$command_name" in
329329
start)
330330
# Parse flags and device name
331331
pure_mode=0
332+
wait_ready=0
332333
device_name=""
333334

334335
while [ $# -gt 0 ]; do
@@ -337,6 +338,10 @@ case "$command_name" in
337338
pure_mode=1
338339
shift
339340
;;
341+
--wait-ready)
342+
wait_ready=1
343+
shift
344+
;;
340345
*)
341346
device_name="$1"
342347
shift
@@ -383,6 +388,24 @@ case "$command_name" in
383388
if [ -n "${ANDROID_EMULATOR_SERIAL:-}" ]; then
384389
echo "$ANDROID_EMULATOR_SERIAL" > "$state_dir/emulator-serial.txt"
385390
fi
391+
392+
# Step 4: If --wait-ready, wait for emulator to be ready and exit (detach mode for dev)
393+
# Otherwise in pure mode, keep running (process-compose manages lifecycle)
394+
if [ "$wait_ready" = "1" ]; then
395+
echo "Waiting for emulator to be ready..."
396+
max_wait=120
397+
elapsed=0
398+
while ! android_emulator_ready; do
399+
sleep 3
400+
elapsed=$((elapsed + 3))
401+
if [ $elapsed -ge $max_wait ]; then
402+
echo "ERROR: Emulator did not become ready within ${max_wait}s" >&2
403+
exit 1
404+
fi
405+
done
406+
echo "✓ Emulator ready and running in background"
407+
exit 0
408+
fi
386409
;;
387410

388411
stop)

plugins/ios/virtenv/scripts/user/ios.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ case "$command_name" in
9898

9999
case "$sub" in
100100
start)
101-
# Parse arguments for device name and --pure flag
101+
# Parse arguments for device name and flags
102102
pure_mode=0
103+
wait_ready=0
103104
device_name=""
104105

105106
while [ $# -gt 0 ]; do
@@ -108,6 +109,10 @@ case "$command_name" in
108109
pure_mode=1
109110
shift
110111
;;
112+
--wait-ready)
113+
wait_ready=1
114+
shift
115+
;;
111116
*)
112117
if [ -z "$device_name" ]; then
113118
device_name="$1"
@@ -234,6 +239,24 @@ case "$command_name" in
234239
echo "$IOS_SIM_UDID" > "$state_dir/simulator-udid.txt"
235240
fi
236241
fi
242+
243+
# If --wait-ready, wait for simulator to be ready and exit (detach mode for dev)
244+
# Otherwise in pure mode, keep running (process-compose manages lifecycle)
245+
if [ "$wait_ready" = "1" ]; then
246+
echo "Waiting for simulator to be ready..."
247+
max_wait=60
248+
elapsed=0
249+
while ! ios_simulator_ready; do
250+
sleep 2
251+
elapsed=$((elapsed + 2))
252+
if [ $elapsed -ge $max_wait ]; then
253+
echo "ERROR: Simulator did not become ready within ${max_wait}s" >&2
254+
exit 1
255+
fi
256+
done
257+
echo "✓ Simulator ready and running in background"
258+
exit 0
259+
fi
237260
;;
238261
stop)
239262
state_dir="$(ios_state_dir)"

0 commit comments

Comments
 (0)