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" client="../bin/dcd-client"
server="../bin/dcd-server" server="../bin/dcd-server"
tcp="" tcp=""
server_pid=""
function startServer() function startServer()
{ {
@ -57,6 +58,24 @@ function startServer()
sleep 1 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 # Make sure that the server is shut down
echo "Shutting down currently-running server..." echo "Shutting down currently-running server..."
"$client" --shutdown 2>/dev/null > /dev/null "$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 for socket in $SOCKETMODES; do # supported: unix tcp
# allow some time for server to shutdown # allow some time for server to shutdown
sleep 0.5; waitShutdown
if [[ $socket == "tcp" ]]; then if [[ $socket == "tcp" ]]; then
tcp="--tcp" tcp="--tcp"
@ -119,6 +138,8 @@ for socket in $SOCKETMODES; do # supported: unix tcp
echo "Shutting down server..." echo "Shutting down server..."
"$client" --shutdown "$tcp" 2>/dev/null > /dev/null "$client" --shutdown "$tcp" 2>/dev/null > /dev/null
waitShutdown
# Report # Report
if [[ $fail_count -eq 0 ]]; then if [[ $fail_count -eq 0 ]]; then
echo -e "${GREEN}${pass_count} tests passed and ${fail_count} failed.${NORMAL}" echo -e "${GREEN}${pass_count} tests passed and ${fail_count} failed.${NORMAL}"