Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrschumacher/9552851 to your computer and use it in GitHub Desktop.
Save jrschumacher/9552851 to your computer and use it in GitHub Desktop.
Travis-CI test for MongoDB connectivity before script
# This script will test for MongoDB connectivity.
# If MongoDB is available then it continues else it tries X times then fails.
#
# Use: Add this to your `before_script` option
before_script:
- |
echo "Testing MongoDB connection...";tries=4;
i=0;
while [ $i -lt $tries ]; do fail=$(mongo --eval db 2>&1 >/dev/null | grep "connect failed");
if [ "$fail" ] && [ $[ $i+1 ] -eq $tries ] ; then echo "Error: Could not connect to mongodb"; exit 1;
elif [ "$fail" ]; then sleep 3; i=$[ $i+1 ];
else echo "OK"; i=$tries; fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment