]> granicus.if.org Git - pgbouncer/commitdiff
test: Restart pgbouncer for every test
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 15 Aug 2019 07:33:44 +0000 (09:33 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 15 Aug 2019 07:33:44 +0000 (09:33 +0200)
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.

test/ssl/test.sh
test/test.sh

index 97d3d3ae88aab7e7f8a22f35457b20955ce422b3..5d03f45576592da9b001dfe5dd096326854e9db9 100755 (executable)
@@ -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
 }
index 6b15af7503b6757637550b07ec6c1851d8ad8747..fbd563f3a8be67570012a208cf43049dbc6b6dae 100755 (executable)
@@ -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
 }