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/*.sql
integration_test/*.sqlite integration_test/*.sqlite
integration_test/*.sqlite3 integration_test/*.sqlite3
integration_test/logs

View file

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