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.
This commit is contained in:
parent
3f7062772d
commit
a59e496024
1 changed files with 33 additions and 5 deletions
|
@ -23,22 +23,50 @@ EOF
|
||||||
cp "$srcdir"/src/lib/global/*.config sandbox/share/empire/builtin
|
cp "$srcdir"/src/lib/global/*.config sandbox/share/empire/builtin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now()
|
||||||
|
{
|
||||||
|
# date +%s isn't portable...
|
||||||
|
perl -e 'printf "%s\n", time'
|
||||||
|
}
|
||||||
|
|
||||||
start_server()
|
start_server()
|
||||||
{
|
{
|
||||||
|
local pidfile=sandbox/var/empire/server.pid
|
||||||
|
local timeout
|
||||||
pid=
|
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
|
src/server/emp_server -e sandbox/etc/empire/econfig -R 1
|
||||||
while src/client/empire red herring 2>&1 | grep -q "Connection refused"
|
timeout=$((`now`+5))
|
||||||
do : # FIXME hangs here if server crashes on startup
|
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
|
||||||
|
if [ `now` -gt $timeout ]
|
||||||
|
then
|
||||||
|
echo "Timed out waiting for server to accept connections" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
pid=`cat sandbox/var/empire/server.pid`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_server()
|
stop_server()
|
||||||
{
|
{
|
||||||
|
local timeout
|
||||||
kill "$pid"
|
kill "$pid"
|
||||||
|
timeout=$((`now`+5))
|
||||||
while kill -0 "$pid" 2>/dev/null
|
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
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue