Skip to content

Commit

Permalink
Ensure that mp_test_executor exits
Browse files Browse the repository at this point in the history
  • Loading branch information
AI0867 committed Oct 4, 2017
1 parent c6408db commit 7b32549
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions utils/travis/mp_test_executor.sh
Expand Up @@ -3,6 +3,9 @@ set -e #Error if any line errors
set -m #Enable job control
set -v #Print shell commands as they are read

TIMEOUT_TIME=300
LOOP_TIME=6

./wesnothd --port 12345 --log-debug=server --log-warning=config &
serverpid=$!

Expand All @@ -12,10 +15,49 @@ hostpid=$!
./wesnoth --plugin=join.lua --server=localhost:12345 --username=join --mp-test --noaddons --nogui &
joinpid=$!

wait $hostpid
START_TIME=$SECONDS
HOST_RUNNING=0
JOIN_RUNNING=0
while true; do
# Timeout
EXEC_TIME=$(($SECONDS - $START_TIME))
if [ $EXEC_TIME -gt $TIMEOUT_TIME ]; then
kill $hostpid 2>/dev/null
kill $joinpid 2>/dev/null
fi
# Check if clients still running
if ! kill -0 $hostpid 2>/dev/null; then
HOST_RUNNING=1
fi
if ! kill -0 $joinpid 2>/dev/null; then
JOIN_RUNNING=1
fi

sleep $LOOP_TIME

# If both are finished, we're done
if ! (kill -0 $hostpid 2>/dev/null || kill -0 $joinpid 2>/dev/null); then
break
fi
# If one has finished previously, kill the other
if [ $HOST_RUNNING == 1 ]; then
echo "Host finished at least $LOOP_TIME seconds ago. Killing join"
kill $joinpid 2>/dev/null
break
fi
if [ $JOIN_RUNNING == 1 ]; then
echo "Join finished at least $LOOP_TIME seconds ago. Killing host"
kill $hostpid 2>/dev/null
break
fi
done

STATUS=0

wait $hostpid || STATUS=1

wait $joinpid
wait $joinpid || STATUS=1

kill $serverpid

exit 0
exit $STATUS

0 comments on commit 7b32549

Please sign in to comment.