Code

integration/test_lib: Manage the sysdbd PID centrally.
authorSebastian Harl <sh@tokkee.org>
Fri, 2 May 2014 15:36:08 +0000 (17:36 +0200)
committerSebastian Harl <sh@tokkee.org>
Fri, 2 May 2014 16:41:50 +0000 (18:41 +0200)
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
t/integration/simple_query.sh
t/integration/test_lib.sh

index 177d934c1d83735ba8fa256fae20d29cc20c5af2..2fb1423ff5a75e20f91f0e35a802ced13e3a2995 100755 (executable)
@@ -37,7 +37,7 @@ cat <<EOF > "$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 <<EOF > "$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
 
index 3be00655392eae11d377cf25acd0172d617dd480..972d246065e2b598972848a11d00d5209f4ce9b1 100755 (executable)
@@ -43,8 +43,7 @@ LoadBackend mock_plugin
 </Backend>
 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
 
index 7bba1515361f804e8444ed717485e87a210841b3..604d2dffb02553a5cc66a09cf8a740f724ee032c 100644 (file)
@@ -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