Refactor integration test names
This commit is contained in:
parent
7422ee9d94
commit
44e20583e6
8
.github/workflows/integration.yml
vendored
8
.github/workflows/integration.yml
vendored
|
@ -19,16 +19,16 @@ jobs:
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install -y shellcheck teeworlds-server
|
sudo apt-get install -y shellcheck teeworlds teeworlds-server
|
||||||
gem install bundler
|
gem install bundler
|
||||||
gem install rubocop:1.31.2
|
gem install rubocop:1.31.2
|
||||||
bundle install --jobs 4 --retry 3
|
bundle install --jobs 4 --retry 3
|
||||||
- name: Test sending chat messages
|
- name: Test sending chat messages
|
||||||
run: |
|
run: |
|
||||||
./integration_test/run.sh chat
|
./integration_test/run.sh client/chat.rb
|
||||||
- name: Test reconnect
|
- name: Test reconnect
|
||||||
run: |
|
run: |
|
||||||
./integration_test/run.sh reconnect
|
./integration_test/run.sh client/reconnect.rb
|
||||||
- name: Test rcon
|
- name: Test rcon
|
||||||
run: |
|
run: |
|
||||||
./integration_test/run.sh rcon
|
./integration_test/run.sh client/rcon.rb
|
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -1,5 +1,8 @@
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
integration_test/*
|
integration_test/*.txt
|
||||||
!integration_test/*.rb
|
integration_test/*.log
|
||||||
!integration_test/*.sh
|
integration_test/*.db
|
||||||
|
integration_test/*.sql
|
||||||
|
integration_test/*.sqlite
|
||||||
|
integration_test/*.sqlite3
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative '../lib/teeworlds_client'
|
require_relative '../../lib/teeworlds_client'
|
||||||
|
|
||||||
client = TeeworldsClient.new(verbose: false)
|
client = TeeworldsClient.new(verbose: false)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative '../lib/teeworlds_client'
|
require_relative '../../lib/teeworlds_client'
|
||||||
|
|
||||||
client = TeeworldsClient.new
|
client = TeeworldsClient.new
|
||||||
|
|
||||||
|
@ -14,5 +14,10 @@ client.on_rcon_line do |ctx|
|
||||||
puts "[rcon] #{ctx.data[:line]}"
|
puts "[rcon] #{ctx.data[:line]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
client.on_disconnect do
|
||||||
|
puts 'got disconnect'
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
# connect and block main thread
|
# connect and block main thread
|
||||||
client.connect('localhost', 8377, detach: false)
|
client.connect('localhost', 8377, detach: false)
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative '../lib/teeworlds_client'
|
require_relative '../../lib/teeworlds_client'
|
||||||
|
|
||||||
client = TeeworldsClient.new(verbose: false)
|
client = TeeworldsClient.new(verbose: false)
|
||||||
|
|
|
@ -2,91 +2,122 @@
|
||||||
|
|
||||||
cd "$(dirname "$0")" || exit 1
|
cd "$(dirname "$0")" || exit 1
|
||||||
|
|
||||||
twbin=teeworlds_srv
|
tw_srv_bin=teeworlds_srv
|
||||||
rubybin=send_chat_hello.rb
|
tw_cl_bin=teeworlds
|
||||||
srvcfg='sv_rcon_password rcon;sv_port 8377;killme'
|
srvcfg='sv_rcon_password rcon;sv_port 8377;killme'
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
echo "[*] shutting down server ..."
|
|
||||||
pkill -f "$twbin $srvcfg"
|
|
||||||
[[ "$_timout_pid" != "" ]] && kill "$_timout_pid" &> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
function timeout() {
|
|
||||||
local seconds="$1"
|
|
||||||
sleep "$seconds"
|
|
||||||
pkill -f "$rubybin"
|
|
||||||
echo "killing: $rubybin"
|
|
||||||
echo "Error: timeouted"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ -x "$(command -v teeworlds_srv)" ]]
|
if [[ -x "$(command -v teeworlds_srv)" ]]
|
||||||
then
|
then
|
||||||
teeworlds_srv "$srvcfg" &> server.txt &
|
teeworlds_srv "$srvcfg" &> server.txt &
|
||||||
elif [[ -x "$(command -v teeworlds-server)" ]]
|
elif [[ -x "$(command -v teeworlds-server)" ]]
|
||||||
then
|
then
|
||||||
teeworlds-server "$srvcfg" &> server.txt &
|
teeworlds-server "$srvcfg" &> server.txt &
|
||||||
twbin='teeworlds-server'
|
tw_srv_bin='teeworlds-server'
|
||||||
elif [[ -x "$(command -v teeworlds-srv)" ]]
|
elif [[ -x "$(command -v teeworlds-srv)" ]]
|
||||||
then
|
then
|
||||||
teeworlds-srv "$srvcfg" &> server.txt &
|
teeworlds-srv "$srvcfg" &> server.txt &
|
||||||
twbin='teeworlds-srv'
|
tw_srv_bin='teeworlds-srv'
|
||||||
else
|
else
|
||||||
echo "Error: please install a teeworlds_srv"
|
echo "Error: please install a teeworlds_srv"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
testname="${1:-chat}"
|
if [[ ! -x "$(command -v "$tw_cl_bin")" ]]
|
||||||
echo "[*] running test '$testname' ..."
|
|
||||||
|
|
||||||
if [ "$testname" == "chat" ]
|
|
||||||
then
|
then
|
||||||
rubybin=send_chat_hello.rb
|
echo "Error: please install a teeworlds"
|
||||||
elif [ "$testname" == "reconnect" ]
|
|
||||||
then
|
|
||||||
rubybin=reconnect.rb
|
|
||||||
elif [ "$testname" == "rcon" ]
|
|
||||||
then
|
|
||||||
rubybin=rcon_shutdown.rb
|
|
||||||
else
|
|
||||||
echo "Error: unkown test '$testname'"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
timeout 3 killme &
|
function get_test_names() {
|
||||||
_timout_pid=$!
|
(find client -name "*.rb";find server -name "*.rb") | tr '\n' ' '
|
||||||
|
}
|
||||||
|
function invalid_test() {
|
||||||
|
local name="$1"
|
||||||
|
echo "Error: invalid test name '$name'"
|
||||||
|
echo " valid tests: $(get_test_names)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
testname="${1:-client/chat.rb}"
|
||||||
|
|
||||||
|
if ! [[ "$testname" =~ (client|server)/.*\.rb$ ]]
|
||||||
|
then
|
||||||
|
invalid_test "$testname"
|
||||||
|
fi
|
||||||
|
if [ ! -f "$testname" ]
|
||||||
|
then
|
||||||
|
testname=${testname##*integration_test/}
|
||||||
|
if [ ! -f "$testname" ]
|
||||||
|
then
|
||||||
|
invalid_test "$testname"
|
||||||
|
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() {
|
||||||
|
echo "[*] shutting down server ..."
|
||||||
|
pkill -f "$tw_srv_bin $srvcfg"
|
||||||
|
[[ "$_timout_pid" != "" ]] && kill "$_timout_pid" &> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
function fail() {
|
function fail() {
|
||||||
local msg="$1"
|
local msg="$1"
|
||||||
|
# the first tail get swalloed
|
||||||
|
# idk why so tail twice to ensure
|
||||||
|
# getting output
|
||||||
|
# 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 client.txt
|
||||||
|
echo "[-] end of server log:"
|
||||||
tail server.txt
|
tail server.txt
|
||||||
echo "$msg"
|
echo "$msg"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$testname" == "chat" ]
|
function timeout() {
|
||||||
|
local seconds="$1"
|
||||||
|
sleep "$seconds"
|
||||||
|
echo "[-] Timeout -> killing: $testname"
|
||||||
|
touch timeout.txt
|
||||||
|
pkill -f "$testname killme"
|
||||||
|
fail "[-] Timeout"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
timeout 3 killme &
|
||||||
|
_timout_pid=$!
|
||||||
|
|
||||||
|
if [ "$testname" == "client/chat.rb" ]
|
||||||
then
|
then
|
||||||
ruby "$rubybin" &> client.txt
|
ruby "$testname" killme &> client.txt
|
||||||
|
|
||||||
if ! grep -q 'hello world' 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" == "reconnect" ]
|
elif [ "$testname" == "client/reconnect.rb" ]
|
||||||
then
|
then
|
||||||
ruby "$rubybin" &> client.txt
|
ruby "$testname" killme &> client.txt
|
||||||
|
|
||||||
if ! grep -q 'bar' 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" == "rcon" ]
|
elif [ "$testname" == "client/rcon.rb" ]
|
||||||
then
|
then
|
||||||
ruby "$rubybin" &> client.txt
|
ruby "$testname" killme &> client.txt
|
||||||
|
|
||||||
if pgrep -f "$twbin $srvcfg"
|
sleep 0.1
|
||||||
|
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"
|
||||||
fi
|
fi
|
||||||
|
@ -95,5 +126,11 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f timeout.txt ]
|
||||||
|
then
|
||||||
|
echo "[-] Error timouted"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[+] Test passed"
|
echo "[+] Test passed"
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,10 @@ class GameClient
|
||||||
@client.send_msg_startinfo
|
@client.send_msg_startinfo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_disconnect
|
||||||
|
@client.hooks[:disconnect]&.call
|
||||||
|
end
|
||||||
|
|
||||||
def on_rcon_line(chunk)
|
def on_rcon_line(chunk)
|
||||||
u = Unpacker.new(chunk.data[1..])
|
u = Unpacker.new(chunk.data[1..])
|
||||||
context = Context.new(
|
context = Context.new(
|
||||||
|
|
|
@ -72,6 +72,10 @@ class TeeworldsClient
|
||||||
@hooks[:connected] = block
|
@hooks[:connected] = block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_disconnect(&block)
|
||||||
|
@hooks[:disconnect] = block
|
||||||
|
end
|
||||||
|
|
||||||
def on_rcon_line(&block)
|
def on_rcon_line(&block)
|
||||||
@hooks[:rcon_line] = block
|
@hooks[:rcon_line] = block
|
||||||
end
|
end
|
||||||
|
@ -301,7 +305,7 @@ class TeeworldsClient
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_msg_close
|
def on_msg_close
|
||||||
puts 'got NET_CTRLMSG_CLOSE'
|
@game_client.on_disconnect
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in a new issue