From a59e4960247ba611690cd9da9fe17288e8db7730 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 25 Mar 2013 16:58:25 +0100 Subject: [PATCH] Make smoke test time out instead of hang when server misbehaves The smoke test waits for the server completing startup by trying to connect until it works. Hangs if the server doesn't complete startup for some reason. Make it give up after 5s. Likewise, The smoke test waits for the server to terminate by trying kill -0 until it fails. Hangs if the server doesn't terminate. Make it give up after 5s. --- tests/test-common.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/test-common.sh b/tests/test-common.sh index d5cf075ee..16864564b 100644 --- a/tests/test-common.sh +++ b/tests/test-common.sh @@ -23,22 +23,50 @@ EOF cp "$srcdir"/src/lib/global/*.config sandbox/share/empire/builtin } +now() +{ + # date +%s isn't portable... + perl -e 'printf "%s\n", time' +} + start_server() { + local pidfile=sandbox/var/empire/server.pid + local timeout pid= - trap 'if [ "$pid" ]; then kill "$pid" 2>/dev/null || true; fi' EXIT + trap 'if [ "$pid" ]; then kill -9 "$pid" 2>/dev/null || true; fi' EXIT src/server/emp_server -e sandbox/etc/empire/econfig -R 1 + timeout=$((`now`+5)) + until pid=`cat $pidfile 2>/dev/null` && [ -n "$pid" ] + do + if [ `now` -gt $timeout ] + then + echo "Timed out waiting for server to create $pidfile" >&2 + exit 1 + fi + done while src/client/empire red herring 2>&1 | grep -q "Connection refused" - do : # FIXME hangs here if server crashes on startup + do + if [ `now` -gt $timeout ] + then + echo "Timed out waiting for server to accept connections" >&2 + exit 1 + fi done - pid=`cat sandbox/var/empire/server.pid` } stop_server() { + local timeout kill "$pid" + timeout=$((`now`+5)) while kill -0 "$pid" 2>/dev/null - do : # FIXME hangs here if server fails to exit + do + if [ `now` -gt $timeout ] + then + echo "Timed out waiting for server to terminate" >&2 + exit 1 + fi done } -- 2.43.0