mirror of
https://github.com/sprockets/sprockets-postgres.git
synced 2024-11-24 03:00:18 +00:00
661a5986c7
1. Add new property function in the ApplicationMixin to indicate if Postgres is connected 2. Add a new guard in the RequestHandlerMixin to check that Postgres is connected prior to executing a query, raising a 503 if it is not 3. Catch OperationalError in RequestHandlerMixin and return 503 for it 4. Timeout when waiting on the connection when attempting to reconnect 5. Log when we're creating a new pool 6. Add debug logging to trace when connectios open 7. Add tests that ensure reconnect logic works as expected
77 lines
1.7 KiB
Bash
Executable file
77 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
set -e
|
|
|
|
# Common constants
|
|
COLOR_RESET='\033[0m'
|
|
COLOR_GREEN='\033[0;32m'
|
|
COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-${PWD##*/}}"
|
|
TEST_HOST="${TEST_HOST:-localhost}"
|
|
|
|
echo "Integration test host: ${TEST_HOST}"
|
|
|
|
get_exposed_port() {
|
|
if [ -z $3 ]
|
|
then
|
|
docker-compose port $1 $2 | cut -d: -f2
|
|
else
|
|
docker-compose port --index=$3 $1 $2 | cut -d: -f2
|
|
fi
|
|
}
|
|
|
|
report_start() {
|
|
printf "Waiting for $1 ... "
|
|
}
|
|
|
|
report_done() {
|
|
printf "${COLOR_GREEN}done${COLOR_RESET}\n"
|
|
}
|
|
|
|
wait_for_healthy_containers() {
|
|
IDs=$(docker-compose ps -q | paste -sd " " -)
|
|
report_start "${1} containers to report healthy"
|
|
counter="0"
|
|
while true
|
|
do
|
|
if [ "$(docker inspect -f "{{.State.Health.Status}}" ${IDs} | grep -c healthy)" -eq "${1}" ]; then
|
|
break
|
|
fi
|
|
counter=$((++counter))
|
|
if [ "${counter}" -eq 120 ]; then
|
|
echo " ERROR: containers failed to start"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
report_done
|
|
}
|
|
|
|
# Ensure Docker is Running
|
|
echo "Docker Information:"
|
|
echo ""
|
|
docker version
|
|
echo ""
|
|
|
|
# Activate the virtual environment
|
|
if test -e env/bin/activate
|
|
then
|
|
. ./env/bin/activate
|
|
fi
|
|
|
|
mkdir -p build
|
|
|
|
# Stop any running instances and clean up after them, then pull images
|
|
docker-compose down --volumes --remove-orphans
|
|
docker-compose up -d --quiet-pull
|
|
|
|
wait_for_healthy_containers 1
|
|
|
|
printf "Loading fixture data ... "
|
|
docker-compose exec postgres psql -q -o /dev/null -U postgres -d postgres -f /fixtures/testing.sql
|
|
report_done
|
|
|
|
cat > build/test-environment<<EOF
|
|
export ASYNC_TEST_TIMEOUT=5
|
|
export POSTGRES_URL=postgresql://postgres@${TEST_HOST}:$(get_exposed_port postgres 5432)/postgres?application_name=sprockets_postgres
|
|
EOF
|
|
|
|
printf "\nBootstrap complete\n\nDon't forget to \"source build/test-environment\"\n"
|