Skip to content

Commit

Permalink
test(e2e, emulator): correctly detect emulator suite startup failure
Browse files Browse the repository at this point in the history
Previously if this script failed it would just retry endlessly and fail a CI run.
Now it correctly determines startup failure and retries 3 times.
Emulator suite shuts itself down after 30 seconds if it didn't starts, determined by experience
  • Loading branch information
mikehardy committed May 18, 2021
1 parent 7dae3f9 commit 7ce15c5
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/scripts/start-firebase-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,34 @@ fi
export STORAGE_EMULATOR_DEBUG=true
EMU_START_COMMAND="firebase emulators:start --only auth,firestore,functions,storage --project react-native-firebase-testing"

IS_CI="${CI}${CONTINUOUS_INTEGRATION}${BUILD_NUMBER}${RUN_ID}"
if [[ -n "${IS_CI}" ]]; then
$EMU_START_COMMAND &
until curl --output /dev/null --silent --fail http://localhost:8080; do
echo "Waiting for Firebase emulator to come online..."
sleep 2
done
echo "Firebase emulator is online!"
else
$EMU_START_COMMAND
fi
MAX_RETRIES=3
MAX_CHECKATTEMPTS=60
CHECKATTEMPTS_WAIT=1

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

if [[ -n "${IS_CI}" ]]; 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

0 comments on commit 7ce15c5

Please sign in to comment.