Skip to content

Commit

Permalink
test(e2d, emulator): fix failure detection on emulator startup
Browse files Browse the repository at this point in the history
This was contributing to E2E flakiness, Related #4058
  • Loading branch information
mikehardy committed May 18, 2021
1 parent eb8d893 commit b73d6ff
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions .github/workflows/scripts/start-firebase-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,36 @@ if ! [ -x "$(command -v firebase)" ]; then
fi

EMU_START_COMMAND="firebase emulators:start --only auth,database,firestore --project react-native-firebase-testing"
#EMU_START_COMMAND="sleep 120"
MAX_RETRIES=3
MAX_CHECKATTEMPTS=60
CHECKATTEMPTS_WAIT=1

if [ "$1" == "--no-daemon" ]; then
$EMU_START_COMMAND
else
$EMU_START_COMMAND &
until curl --output /dev/null --silent --fail http://localhost:8080; do
echo "Waiting for Firestore emulator to come online..."
sleep 2
done
echo "Firestore emulator is online!"
fi

RETRIES=1
while [ $RETRIES -le $MAX_RETRIES ]; do

if [ "$1" == "--no-daemon" ]; then
echo "Starting Firebase Emulator Suite in foreground."
$EMU_START_COMMAND
else
echo "Starting Firebase Emulator Suite in background."
$EMU_START_COMMAND &
CHECKATTEMPTS=1
while [ $CHECKATTEMPTS -le $MAX_CHECKATTEMPTS ]; do
sleep $CHECKATTEMPTS_WAIT
if curl --output /dev/null --silent --fail http://localhost:8080; then
echo "Firebase Emulator Suite is online!"
exit 0;
fi
echo "Waiting for Firebase Emulator Suite to come online, check $CHECKATTEMPTS of $MAX_CHECKATTEMPTS..."
((CHECKATTEMPTS = CHECKATTEMPTS + 1))
done
fi

echo "Firebase Emulator Suite did not come online in $MAX_CHECKATTEMPTS checks. Try $RETRIES of $MAX_RETRIES."
((RETRIES = RETRIES + 1))

done
echo "Firebase Emulator Suite did not come online after $MAX_RETRIES attempts."
exit 1

1 comment on commit b73d6ff

@vercel
Copy link

@vercel vercel bot commented on b73d6ff May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.