@@ -12,7 +12,7 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
12
12
# Read the absolute path to the exporter
13
13
postgres_exporter=$( readlink -f $1 )
14
14
test_binary=$( readlink -f $2 )
15
- POSTGRES_PASSWORD=postgres
15
+ export POSTGRES_PASSWORD=postgres
16
16
exporter_port=9187
17
17
18
18
cd $DIR
@@ -26,53 +26,35 @@ VERSIONS=( \
26
26
9.6 \
27
27
)
28
28
29
- wait_for_replicated_postgres () {
30
- local CONTAINER_NAME=$1
31
- if [ -z $CONTAINER_NAME ]; then
32
- echo " No container name specified." 1>&2
29
+ wait_for_postgres (){
30
+ local ip=$1
31
+ local port=$2
32
+ if [ -z $ip ]; then
33
+ echo " No IP specified." 1>&2
33
34
exit 1
34
35
fi
35
- local WAIT_START=$( date +%s)
36
- echo " Waiting for postgres to initialize..."
37
- while ! docker exec $CONTAINER_NAME bash -c " test -e /tmp/.postgres_init_complete" ; do
38
- if [ $(( $(date +% s) - $WAIT_START )) -gt $TIMEOUT ]; then
39
- echo " Timed out waiting for postgres!" 1>&2
40
- exit 1
41
- fi
42
- sleep 1
43
- done
44
- echo " Waiting for postgres to start..."
45
- while ! docker exec $CONTAINER_NAME bash -c " psql -U postgres -c \" select 'running'\" > /dev/null 2>&1 " ; do
46
- if [ $(( $(date +% s) - $WAIT_START )) -gt $TIMEOUT ]; then
47
- echo " Timed out waiting for postgres!" 1>&2
48
- exit 1
49
- fi
50
- sleep 1
51
- done
52
- }
53
-
54
- wait_for_postgres () {
55
- local CONTAINER_NAME=$1
56
- if [ -z $CONTAINER_NAME ]; then
57
- echo " No container name specified." 1>&2
36
+
37
+ if [ -z $port ]; then
38
+ echo " No port specified." 1>&2
58
39
exit 1
59
40
fi
60
- local WAIT_START=$( date +%s)
61
- echo " Waiting for postgres to start..."
62
- while ! docker exec $CONTAINER_NAME bash -c " psql -U postgres -c \" select 'running'\" > /dev/null 2>&1 " ; do
63
- if [ $(( $(date +% s) - $WAIT_START )) -gt $TIMEOUT ]; then
64
- echo " Timed out waiting for postgres!" 1>&2
65
- exit 1
41
+
42
+ local wait_start=$( date +%s)
43
+ echo " Waiting for postgres to start listening..."
44
+ while ! pg_isready --host=$ip --port=$port & > /dev/null; do
45
+ if [ $(( $(date +% s) - $wait_start )) -gt $TIMEOUT ]; then
46
+ echo " Timed out waiting for postgres to start!" 1>&2
47
+ exit 1
66
48
fi
67
49
sleep 1
68
- done
50
+ done
69
51
}
70
52
71
53
wait_for_exporter () {
72
- local DAEMON_WAIT_START =$( date +%s)
54
+ local wait_start =$( date +%s)
73
55
echo " Waiting for exporter to start..."
74
56
while ! nc -z localhost $exporter_port ; do
75
- if [ $(( $(date +% s) - $DAEMON_WAIT_START )) -gt $TIMEOUT ]; then
57
+ if [ $(( $(date +% s) - $wait_start )) -gt $TIMEOUT ]; then
76
58
echo " Timed out waiting for exporter!" 1>&2
77
59
exit 1
78
60
fi
@@ -91,12 +73,12 @@ smoketest_postgres() {
91
73
echo " #######################"
92
74
echo " Standalone Postgres $version "
93
75
echo " #######################"
94
- local docker_cmd=' docker run -d -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 $CUR_IMAGE'
76
+ local docker_cmd=" docker run -d -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 $CUR_IMAGE "
95
77
echo " Docker Cmd: $docker_cmd "
96
78
97
- CONTAINER_NAME=$( eval $docker_cmd )
79
+ CONTAINER_NAME=$( $docker_cmd )
98
80
trap " docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm -v $CONTAINER_NAME ; exit 1" EXIT INT TERM
99
- wait_for_postgres $CONTAINER_NAME
81
+ wait_for_postgres localhost 55432
100
82
101
83
DATA_SOURCE_NAME=" postgresql://postgres:$POSTGRES_PASSWORD @localhost:55432/?sslmode=disable" $test_binary --log.level=debug || exit $?
102
84
# exporter_pid=$!
@@ -112,7 +94,7 @@ smoketest_postgres() {
112
94
#
113
95
# kill $exporter_pid
114
96
docker kill $CONTAINER_NAME
115
- docker rm $CONTAINER_NAME
97
+ docker rm -v $CONTAINER_NAME
116
98
trap - EXIT INT TERM
117
99
118
100
echo " #######################"
@@ -134,9 +116,10 @@ smoketest_postgres() {
134
116
master_container=$( docker-compose ps -q pg-master)
135
117
slave_container=$( docker-compose ps -q pg-slave)
136
118
master_ip=$( docker inspect -f ' {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $master_container )
119
+ slave_ip=$( docker inspect -f ' {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $slave_container )
137
120
echo " Got master IP: $master_ip "
138
- wait_for_replicated_postgres $master_container
139
- wait_for_replicated_postgres $slave_container
121
+ wait_for_postgres $master_ip 5432
122
+ wait_for_postgres $slave_ip 5432
140
123
141
124
DATA_SOURCE_NAME=" postgresql://postgres:$POSTGRES_PASSWORD @$master_ip :5432/?sslmode=disable" $test_binary --log.level=debug || exit $?
142
125
# exporter_pid=$!
0 commit comments