Fix the errors introduced into smoke-test from the refactor.

This commit is contained in:
Will Rouesnel 2018-11-11 15:33:27 +11:00
parent ae8bea6eb8
commit 99ff02c6a9
No known key found for this signature in database
GPG Key ID: 72DC65802A1091C5
1 changed files with 23 additions and 18 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -x
# Basic integration tests with postgres. Requires docker to work.
SOURCE="${BASH_SOURCE[0]}"
@ -38,12 +38,12 @@ VERSIONS=( \
wait_for_postgres(){
local ip=$1
local port=$2
if [ -z $ip ]; then
if [ -z "$ip" ]; then
echo "No IP specified." 1>&2
exit 1
fi
if [ -z $port ]; then
if [ -z "$port" ]; then
echo "No port specified." 1>&2
exit 1
fi
@ -51,26 +51,28 @@ 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
if [ $(( $(date +%s) - $wait_start )) -gt $TIMEOUT ]; then
while ! 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
fi
sleep 1
done
echo "Postgres is online at $ip:$port"
}
wait_for_exporter() {
local wait_start
wait_start=$(date +%s) || exit 1
echo "Waiting for exporter to start..."
while ! nc -z localhost $exporter_port ; do
if [ $(( $(date +%s) - $wait_start )) -gt $TIMEOUT ]; then
while ! nc -z localhost "$exporter_port" ; do
if [ $(( $(date +%s) - wait_start )) -gt "$TIMEOUT" ]; then
echo "Timed out waiting for exporter!" 1>&2
exit 1
fi
sleep 1
done
echo "Exporter is online at localhost:$exporter_port"
}
smoketest_postgres() {
@ -89,22 +91,24 @@ smoketest_postgres() {
CONTAINER_NAME=$($docker_cmd)
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 "$standalone_ip" 5432
# Run the test binary.
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$standalone_ip:5432/?sslmode=disable" $test_binary || exit $?
# Extract a raw metric list.
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$standalone_ip:5432/?sslmode=disable" $postgres_exporter --log.level=debug --web.listen-address=:$exporter_port &
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$standalone_ip:5432/?sslmode=disable" $postgres_exporter \
--log.level=debug --web.listen-address=:$exporter_port &
exporter_pid=$!
# shellcheck disable=SC2064
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm -v $CONTAINER_NAME; kill $exporter_pid; exit 1" EXIT INT TERM
wait_for_exporter
# Dump the metrics to a file.
if wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.single.$version.prom" ; then
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
if ! wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.single.$version.prom" ; then
echo "Failed on postgres $version (standalone $DOCKER_IMAGE)" 1>&2
kill $exporter_pid
exit 1
fi
@ -117,8 +121,8 @@ smoketest_postgres() {
fi
kill $exporter_pid
docker kill $CONTAINER_NAME
docker rm -v $CONTAINER_NAME
docker kill "$CONTAINER_NAME"
docker rm -v "$CONTAINER_NAME"
trap - EXIT INT TERM
echo "#######################"
@ -127,7 +131,7 @@ smoketest_postgres() {
old_pwd=$(pwd)
cd docker-postgres-replication || exit 1
if VERSION="$version" p2 -t Dockerfile.p2 -o Dockerfile ; then
if ! VERSION="$version" p2 -t Dockerfile.p2 -o Dockerfile ; then
echo "Templating failed" 1>&2
exit 1
fi
@ -146,14 +150,15 @@ smoketest_postgres() {
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter --log.level=debug --web.listen-address=:$exporter_port &
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter \
--log.level=debug --web.listen-address=:$exporter_port &
exporter_pid=$!
# shellcheck disable=SC2064
trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
wait_for_exporter
if wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.replicated.$version.prom" ; then
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
if ! wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.replicated.$version.prom" ; then
echo "Failed on postgres $version (replicated $DOCKER_IMAGE)" 1>&2
exit 1
fi