Skip to content

Commit

Permalink
Fix smoke-tests to more reliably use pg_isready.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrouesnel committed Jul 3, 2019
1 parent bb8b37c commit 0d7891d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM postgres:10
FROM postgres:11
MAINTAINER Daniel Dent (https://www.danieldent.com)
ENV PG_MAX_WAL_SENDERS 8
ENV PG_WAL_KEEP_SEGMENTS 8
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y inetutils-ping
COPY setup-replication.sh /docker-entrypoint-initdb.d/
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint-initdb.d/setup-replication.sh /docker-entrypoint.sh
15 changes: 8 additions & 7 deletions cmd/postgres_exporter/tests/test-smoke
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -x
# Basic integration tests with postgres. Requires docker to work.

SOURCE="${BASH_SOURCE[0]}"
Expand Down Expand Up @@ -34,8 +34,9 @@ VERSIONS=( \
)

wait_for_postgres(){
local ip=$1
local port=$2
local container=$1
local ip=$2
local port=$3
if [ -z "$ip" ]; then
echo "No IP specified." 1>&2
exit 1
Expand All @@ -49,7 +50,7 @@ wait_for_postgres(){
local wait_start
wait_start=$(date +%s) || exit 1
echo "Waiting for postgres to start listening..."
while ! pg_isready --host="$ip" --port="$port" &> /dev/null; do
while ! docker exec "$container" pg_isready --host="$ip" --port="$port" &> /dev/null; do
if [ $(( $(date +%s) - wait_start )) -gt "$TIMEOUT" ]; then
echo "Timed out waiting for postgres to start!" 1>&2
exit 1
Expand Down Expand Up @@ -91,7 +92,7 @@ smoketest_postgres() {
standalone_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_NAME)
# shellcheck disable=SC2064
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm -v $CONTAINER_NAME; exit 1" EXIT INT TERM
wait_for_postgres "$standalone_ip" 5432
wait_for_postgres "$CONTAINER_NAME" "$standalone_ip" 5432

# Run the test binary.
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$standalone_ip:5432/?sslmode=disable" $test_binary || exit $?
Expand Down Expand Up @@ -143,8 +144,8 @@ smoketest_postgres() {
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$master_container")
slave_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$slave_container")
echo "Got master IP: $master_ip"
wait_for_postgres "$master_ip" 5432
wait_for_postgres "$slave_ip" 5432
wait_for_postgres "$master_container" "$master_ip" 5432
wait_for_postgres "$slave_container" "$slave_ip" 5432

DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?

Expand Down

0 comments on commit 0d7891d

Please sign in to comment.