From: Peter Eisentraut Date: Thu, 15 Aug 2019 07:33:44 +0000 (+0200) Subject: test: Restart pgbouncer for every test X-Git-Tag: pgbouncer_1_11_0~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02b388ba563729995bcfd1cb3cb95aa524b24224;p=pgbouncer test: Restart pgbouncer for every test There are too many cases where existing pool states lingers between one test and another, making some test results unreliable. It's safer to just restart the whole process to get a clean start. This also lets us mark the pgbouncer log file with where a test began and ended. --- diff --git a/test/ssl/test.sh b/test/ssl/test.sh index 97d3d3a..5d03f45 100755 --- a/test/ssl/test.sh +++ b/test/ssl/test.sh @@ -34,9 +34,18 @@ pgctl() { ulimit -c unlimited -for f in pgdata/postmaster.pid test.pid; do - test -f $f && { kill `head -n1 $f` || true; } -done +stopit() { + local pid + if test -f "$1"; then + pid=`head -n1 "$1"` + kill $pid + while kill -0 $pid 2>/dev/null; do sleep 0.1; done + rm -f "$1" + fi +} + +stopit test.pid +stopit pgdata/postmaster.pid mkdir -p $LOGDIR rm -f $BOUNCER_LOG $PG_LOG @@ -73,9 +82,6 @@ psql -X -p $PG_PORT -l | grep p0 > /dev/null || { createdb -p $PG_PORT p1 } -$BOUNCER_EXE -d $BOUNCER_INI -sleep 1 - reconf_bouncer() { cp test.ini tmp/test.ini for ln in "$@"; do @@ -124,7 +130,11 @@ admin() { runtest() { local status + $BOUNCER_EXE -d $BOUNCER_INI + until psql -X -h /tmp -U pgbouncer -d pgbouncer -c "show version" 2>/dev/null 1>&2; do sleep 0.1; done + printf "`date` running $1 ... " + echo "# $1 begin" >>$BOUNCER_LOG eval $1 >$LOGDIR/$1.log 2>&1 status=$? if [ $status -eq 0 ]; then @@ -137,8 +147,9 @@ runtest() { # allow background processing to complete wait - # start with fresh config - kill -HUP `cat $BOUNCER_PID` + + stopit test.pid + echo "# $1 end" >>$BOUNCER_LOG return $status } diff --git a/test/test.sh b/test/test.sh index 6b15af7..fbd563f 100755 --- a/test/test.sh +++ b/test/test.sh @@ -66,7 +66,13 @@ Linux) esac stopit() { - test -f "$1" && { kill `head -n1 "$1"`; rm -f "$1"; } + local pid + if test -f "$1"; then + pid=`head -n1 "$1"` + kill $pid + while kill -0 $pid 2>/dev/null; do sleep 0.1; done + rm -f "$1" + fi } stopit test.pid @@ -116,10 +122,6 @@ psql -X -p $PG_PORT -d p0 -c "select * from pg_user" | grep pswcheck > /dev/null psql -X -o /dev/null -p $PG_PORT -c "create user puser2 password 'wrong';" p0 || exit 1 } -echo "Starting bouncer" -$BOUNCER_EXE -d $BOUNCER_INI -sleep 1 - # # fw hacks # @@ -182,7 +184,11 @@ admin() { runtest() { local status + $BOUNCER_EXE -d $BOUNCER_INI + until psql -X -h /tmp -U pgbouncer -d pgbouncer -c "show version" 2>/dev/null 1>&2; do sleep 0.1; done + printf "`date` running $1 ... " + echo "# $1 begin" >>$BOUNCER_LOG eval $1 >$LOGDIR/$1.log 2>&1 status=$? if [ $status -eq 0 ]; then @@ -197,8 +203,9 @@ runtest() { # allow background processing to complete wait - # start with fresh config - kill -HUP `cat $BOUNCER_PID` + + stopit test.pid + echo "# $1 end" >>$BOUNCER_LOG return $status }