Skip to content

Commit b73d6ff

Browse files
committed
test(e2d, emulator): fix failure detection on emulator startup
This was contributing to E2E flakiness, Related #4058
1 parent eb8d893 commit b73d6ff

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

.github/workflows/scripts/start-firebase-emulator.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,36 @@ if ! [ -x "$(command -v firebase)" ]; then
55
fi
66

77
EMU_START_COMMAND="firebase emulators:start --only auth,database,firestore --project react-native-firebase-testing"
8+
#EMU_START_COMMAND="sleep 120"
9+
MAX_RETRIES=3
10+
MAX_CHECKATTEMPTS=60
11+
CHECKATTEMPTS_WAIT=1
812

9-
if [ "$1" == "--no-daemon" ]; then
10-
$EMU_START_COMMAND
11-
else
12-
$EMU_START_COMMAND &
13-
until curl --output /dev/null --silent --fail http://localhost:8080; do
14-
echo "Waiting for Firestore emulator to come online..."
15-
sleep 2
16-
done
17-
echo "Firestore emulator is online!"
18-
fi
13+
14+
RETRIES=1
15+
while [ $RETRIES -le $MAX_RETRIES ]; do
16+
17+
if [ "$1" == "--no-daemon" ]; then
18+
echo "Starting Firebase Emulator Suite in foreground."
19+
$EMU_START_COMMAND
20+
else
21+
echo "Starting Firebase Emulator Suite in background."
22+
$EMU_START_COMMAND &
23+
CHECKATTEMPTS=1
24+
while [ $CHECKATTEMPTS -le $MAX_CHECKATTEMPTS ]; do
25+
sleep $CHECKATTEMPTS_WAIT
26+
if curl --output /dev/null --silent --fail http://localhost:8080; then
27+
echo "Firebase Emulator Suite is online!"
28+
exit 0;
29+
fi
30+
echo "Waiting for Firebase Emulator Suite to come online, check $CHECKATTEMPTS of $MAX_CHECKATTEMPTS..."
31+
((CHECKATTEMPTS = CHECKATTEMPTS + 1))
32+
done
33+
fi
34+
35+
echo "Firebase Emulator Suite did not come online in $MAX_CHECKATTEMPTS checks. Try $RETRIES of $MAX_RETRIES."
36+
((RETRIES = RETRIES + 1))
37+
38+
done
39+
echo "Firebase Emulator Suite did not come online after $MAX_RETRIES attempts."
40+
exit 1

0 commit comments

Comments
 (0)