]> granicus.if.org Git - pgbouncer/commitdiff
test.sh: Sort out netcat zoo
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 26 Jul 2018 11:56:30 +0000 (13:56 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 26 Jul 2018 11:56:30 +0000 (13:56 +0200)
The previous code distinguished between Linux and non-Linux netcat.
This didn't stand the test of time, since Linux distributions now ship
multiple variants of netcat and other operating systems also provide
multiple options.  So instead try to detect the variant from the help
output.  Also, the previous uses of the -q and -w options behaved
strangely with some versions and/or were inconsistent with the
documentation.  So abandon those options and just rely on the existing
killall call.

The test_server_connect_timeout_establish test should now pass again on
hopefully most configurations.

test/test.sh

index b1d16ff2d12a0238265a14155155ce139c3df4fa..00dc62c645bc6b57b3109ba81c96cd30d324a922 100755 (executable)
@@ -61,11 +61,9 @@ fi
 
 # System configuration checks
 SED_ERE_OP='-E'
-NC_WAIT_OP='-w 5'
 case `uname` in
 Linux)
        SED_ERE_OP='-r'
-       NC_WAIT_OP='-q 5'
        ;;
 esac
 
@@ -237,17 +235,23 @@ test_server_login_retry() {
 # server_connect_timeout - uses netcat to start dummy server
 test_server_connect_timeout_establish() {
        which nc >/dev/null || return 1
-
-       echo nc $NC_WAIT_OP -l $NC_PORT
-       nc $NC_WAIT_OP -l $NC_PORT >/dev/null &
+       if nc -h 2>&1 | grep -q 'nc -l -p port'; then
+               # traditional or GNU style
+               set -- nc -l -p $NC_PORT
+       else
+               # BSD style
+               set -- nc -l $NC_PORT
+       fi
+       echo "$@"
+       "$@" >/dev/null &
        sleep 2
+
        admin "set query_timeout=3"
        admin "set server_connect_timeout=2"
        psql -X -c "select now()" p2
        # client will always see query_timeout, need to grep for connect timeout
        grep "closing because: connect timeout" $BOUNCER_LOG
        rc=$?
-       # didnt seem to die otherwise
        killall nc
        return $rc
 }