properly wait for server shutdown in CI

This commit is contained in:
WebFreak001 2023-03-22 02:35:40 +01:00
parent 20df158917
commit 2ff1291b09
No known key found for this signature in database
GPG Key ID: AEFC88D11109D1AA
1 changed files with 22 additions and 1 deletions

View File

@ -44,6 +44,7 @@ pass_count=0
client="../bin/dcd-client"
server="../bin/dcd-server"
tcp=""
server_pid=""
function startServer()
{
@ -57,6 +58,24 @@ function startServer()
sleep 1
}
function waitShutdown()
{
if [[ -z "$server_pid" ]]; then
sleep 0.5 # not owned by us
else
( sleep 15 ; echo 'Waiting for shutdown timed out'; kill $server_pid ) &
killerPid=$!
wait $server_pid
status=$?
(kill -0 $killerPid && kill $killerPid) || true
server_pid=""
return $status
fi
}
# Make sure that the server is shut down
echo "Shutting down currently-running server..."
"$client" --shutdown 2>/dev/null > /dev/null
@ -64,7 +83,7 @@ echo "Shutting down currently-running server..."
for socket in $SOCKETMODES; do # supported: unix tcp
# allow some time for server to shutdown
sleep 0.5;
waitShutdown
if [[ $socket == "tcp" ]]; then
tcp="--tcp"
@ -119,6 +138,8 @@ for socket in $SOCKETMODES; do # supported: unix tcp
echo "Shutting down server..."
"$client" --shutdown "$tcp" 2>/dev/null > /dev/null
waitShutdown
# Report
if [[ $fail_count -eq 0 ]]; then
echo -e "${GREEN}${pass_count} tests passed and ${fail_count} failed.${NORMAL}"