From 63c6c74e57ae1f2b6133fbd20e31201f0a0d8612 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 2 May 2014 17:36:08 +0200 Subject: [PATCH] integration/test_lib: Manage the sysdbd PID centrally. This way, we actually get the right PID outside of the wrapper function and test_lib can make sure the process is terminated on EXIT. --- t/integration/simple_config.sh | 8 +++----- t/integration/simple_query.sh | 6 ++---- t/integration/test_lib.sh | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/t/integration/simple_config.sh b/t/integration/simple_config.sh index 177d934..2fb1423 100755 --- a/t/integration/simple_config.sh +++ b/t/integration/simple_config.sh @@ -37,7 +37,7 @@ cat < "$SYSDBD_CONF" Listen "invalid://address" EOF -if run_sysdbd -D -C "$SYSDBD_CONF"; then +if run_sysdbd_foreground -D -C "$SYSDBD_CONF"; then echo 'SysDBd accepted invalid listen address; expected: failure' >&2 exit 1 fi @@ -46,10 +46,8 @@ cat < "$SYSDBD_CONF" Listen "$SOCKET_FILE" EOF -run_sysdbd -D -C "$SYSDBD_CONF" & -sysdbd_pid=$! +run_sysdbd -D -C "$SYSDBD_CONF" wait_for_sysdbd -kill $sysdbd_pid -wait $sysdbd_pid +stop_sysdbd diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index 3be0065..972d246 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -43,8 +43,7 @@ LoadBackend mock_plugin EOF -run_sysdbd -D -C "$SYSDBD_CONF" & -sysdbd_pid=$! +run_sysdbd -D -C "$SYSDBD_CONF" wait_for_sysdbd sleep 3 @@ -117,6 +116,5 @@ output="$( run_sysdb -H "$SOCKET_FILE" \ -c "LOOKUP hosts WHERE attribute.invalid = 'none'" )" echo $output | grep -E '^\[\]$' -kill $sysdbd_pid -wait $sysdbd_pid +stop_sysdbd diff --git a/t/integration/test_lib.sh b/t/integration/test_lib.sh index 7bba151..604d2df 100644 --- a/t/integration/test_lib.sh +++ b/t/integration/test_lib.sh @@ -30,7 +30,7 @@ TOP_SRCDIR="$( readlink -f "$( dirname "$0" )/../.." )" TESTDIR="$( mktemp -d )" -trap "rm -rf '$TESTDIR'" EXIT +trap "rm -rf '$TESTDIR'; test -z \$SYSDBD_PID || kill \$SYSDBD_PID" EXIT mkdir "$TESTDIR/backend" cp "$TOP_SRCDIR/t/integration/.libs/mock_plugin.so" "$TESTDIR/backend" @@ -55,9 +55,24 @@ function run_sysdb() { } function run_sysdbd() { + LD_PRELOAD=$TESTDIR/libsysdb.so $MEMCHECK "$TESTDIR/sysdbd" "$@" & + SYSDBD_PID=$! +} + +function run_sysdbd_foreground() { LD_PRELOAD=$TESTDIR/libsysdb.so $MEMCHECK "$TESTDIR/sysdbd" "$@" } +function stop_sysdbd() { + if test -z $SYSDBD_PID; then + echo "Cannot stop sysdbd; PID unknown" >&2 + exit 1 + fi + kill $SYSDBD_PID + wait $SYSDBD_PID + SYSDBD_PID='' +} + function wait_for_sysdbd() { local i for (( i=0; i<10; i++ )); do -- 2.30.2