More integration test refactors

This commit is contained in:
ChillerDragon 2022-11-12 18:31:40 +01:00
parent 44e20583e6
commit 5fda2dcde1
2 changed files with 59 additions and 41 deletions

1
.gitignore vendored
View file

@ -5,4 +5,5 @@ integration_test/*.db
integration_test/*.sql
integration_test/*.sqlite
integration_test/*.sqlite3
integration_test/logs

View file

@ -5,28 +5,43 @@ cd "$(dirname "$0")" || exit 1
tw_srv_bin=teeworlds_srv
tw_cl_bin=teeworlds
srvcfg='sv_rcon_password rcon;sv_port 8377;killme'
clcfg='connect 127.0.0.1:8377;killme'
tw_srv_running=0
tw_client_running=0
logdir=logs
mkdir -p logs
function start_tw_server() {
if [[ -x "$(command -v teeworlds_srv)" ]]
then
teeworlds_srv "$srvcfg" &> server.txt &
teeworlds_srv "$srvcfg" &> "$logdir/server.txt" &
elif [[ -x "$(command -v teeworlds-server)" ]]
then
teeworlds-server "$srvcfg" &> server.txt &
teeworlds-server "$srvcfg" &> "$logdir/server.txt" &
tw_srv_bin='teeworlds-server'
elif [[ -x "$(command -v teeworlds-srv)" ]]
then
teeworlds-srv "$srvcfg" &> server.txt &
teeworlds-srv "$srvcfg" &> "$logdir/server.txt" &
tw_srv_bin='teeworlds-srv'
else
echo "Error: please install a teeworlds_srv"
exit 1
fi
tw_srv_running=1
}
if [[ ! -x "$(command -v "$tw_cl_bin")" ]]
function connect_tw_client() {
if [[ -x "$(command -v teeworlds)" ]]
then
teeworlds "$clcfg"
tw_cl_bin=teeworlds
else
echo "Error: please install a teeworlds"
exit 1
fi
tw_client_running=1
}
function get_test_names() {
(find client -name "*.rb";find server -name "*.rb") | tr '\n' ' '
@ -53,14 +68,17 @@ then
fi
fi
echo "[*] running test '$testname' ..."
echo "client log $(date)" > client.txt
echo "server log $(date)" > server.txt
[[ -f timeout.txt ]] && rm timeout.txt
function cleanup() {
if [ "$tw_srv_running" == "1" ]
then
echo "[*] shutting down server ..."
pkill -f "$tw_srv_bin $srvcfg"
fi
if [ "$tw_client_running" == "1" ]
then
echo "[*] shutting down client ..."
pkill -f "$tw_cl_bin $clcfg"
fi
[[ "$_timout_pid" != "" ]] && kill "$_timout_pid" &> /dev/null
}
@ -74,11 +92,11 @@ function fail() {
# this is a bit ugly but it works
# maybe a sleep does as well
# or I still did not get flushing
tail client.txt &>/dev/null
echo "[-] end of client log:"
tail client.txt
tail "$logdir/ruby_client.txt" &>/dev/null
echo "[-] end of ruby client log:"
tail "$logdir/ruby_client.txt"
echo "[-] end of server log:"
tail server.txt
tail "$logdir/server.txt"
echo "$msg"
exit 1
}
@ -92,31 +110,30 @@ function timeout() {
fail "[-] Timeout"
}
echo "[*] running test '$testname' ..."
echo "ruby client log $(date)" > "$logdir/ruby_client.txt"
echo "server log $(date)" > "$logdir/server.txt"
[[ -f timeout.txt ]] && rm timeout.txt
start_tw_server
timeout 3 killme &
_timout_pid=$!
ruby "$testname" killme &> "$logdir/ruby_client.txt"
if [ "$testname" == "client/chat.rb" ]
then
ruby "$testname" killme &> client.txt
if ! grep -q 'hello world' server.txt
if ! grep -q 'hello world' "$logdir/server.txt"
then
fail "Error: did not find chat message in server log"
fi
elif [ "$testname" == "client/reconnect.rb" ]
then
ruby "$testname" killme &> client.txt
if ! grep -q 'bar' server.txt
if ! grep -q 'bar' "$logdir/server.txt"
then
fail "Error: did not find 2nd chat message in server log"
fi
elif [ "$testname" == "client/rcon.rb" ]
then
ruby "$testname" killme &> client.txt
sleep 0.1
sleep 1
if pgrep -f "$tw_srv_bin $srvcfg"
then
fail "Error: server still running rcon shutdown failed"