Poll for the database to be up before running tests

This commit is contained in:
Matt Rogers 2018-05-30 08:21:21 -05:00
parent 9f65d809da
commit 49bc3eb0cd
No known key found for this signature in database
GPG key ID: 605D017C07EB4316
2 changed files with 19 additions and 1 deletions

View file

@ -7,6 +7,12 @@ function cleanup() {
$docker_compose down $docker_compose down
} }
function die() {
echo $@
exit 1
}
trap cleanup EXIT trap cleanup EXIT
export RAILS_ENV=test export RAILS_ENV=test
@ -16,7 +22,7 @@ cp config/site.yml.tmpl config/site.yml
$docker_compose build $docker_compose build
$docker_compose up -d $docker_compose up -d
sleep 5 # janky way of waiting for the database to be up script/poll-for-db
# Leaving this in since it will be needed for Rails 5 # Leaving this in since it will be needed for Rails 5
# bin/rails db:environment:set RAILS_ENV=test || true # bin/rails db:environment:set RAILS_ENV=test || true

12
script/poll-for-db Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
appdir=$(cd $(dirname "$0")/.. && pwd)
[ -f /etc/app-env ] || exec "$appdir/script/docker-environment" $0 $@
for i in {1..60}; do
curl -sf db:3306 >/dev/null && exit
sleep 1
done
echo "Unable to reach database!"
exit 1