Skip to content

Commit 702531f

Browse files
committed
Add failing server side integration test
1 parent 0dcb85a commit 702531f

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

.github/workflows/integration.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ jobs:
3232
unzip DDNet-headless.zip
3333
sudo mv DDNet-headless /usr/local/bin
3434
rm DDNet-headless.zip
35-
- name: Test sending chat messages
35+
wget https://github.com/ChillerDragon/ddnet/releases/download/v17.4.2-headless-0.7/DDNet7-headless.zip
36+
unzip DDNet7-headless.zip
37+
sudo mv DDNet7-headless /usr/local/bin
38+
rm DDNet7-headless.zip
39+
- name: [CLIENT] Test sending chat messages
3640
run: |
3741
./integration_test/run.sh client/chat.rb
38-
- name: Test reconnect
42+
- name: [CLIENT] Test reconnect
3943
run: |
4044
./integration_test/run.sh client/reconnect.rb
41-
- name: Test rcon
45+
- name: [CLIENT] Test rcon
4246
run: |
43-
./integration_test/run.sh client/rcon.rb
47+
./integration_test/run.sh client/rcon.rb
48+
- name: [SERVER] Test connect
49+
run: |
50+
./integration_test/run.sh server/connect.rb

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ integration_test/*.db
88
integration_test/*.sql
99
integration_test/*.sqlite
1010
integration_test/*.sqlite3
11+
integration_test/*.fifo
1112
integration_test/logs
13+
integration_test/tmp
1214

integration_test/run.sh

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ cd "$(dirname "$0")" || exit 1
44

55
tw_srv_bin=teeworlds_srv
66
tw_cl_bin=teeworlds
7+
logdir=logs
8+
tmpdir=tmp
79
srvcfg='sv_rcon_password rcon;sv_port 8377;killme'
8-
clcfg='connect 127.0.0.1:8377;killme'
10+
cl_fifo="$tmpdir/client.fifo"
11+
clcfg="cl_input_fifo $cl_fifo;connect 127.0.0.1:8377;killme"
912
tw_srv_running=0
1013
tw_client_running=0
11-
logdir=logs
1214
ruby_logfile=ruby_client.txt
1315

1416
mkdir -p logs
17+
mkdir -p tmp
1518

1619
function start_tw_server() {
1720
if [[ -x "$(command -v teeworlds_srv)" ]]
@@ -35,11 +38,11 @@ function start_tw_server() {
3538
function connect_tw_client() {
3639
if [[ -x "$(command -v teeworlds-headless)" ]]
3740
then
38-
teeworlds-headless "$clcfg" "$logdir/client.txt"
41+
teeworlds-headless "$clcfg"
3942
tw_cl_bin=teeworlds-headless
4043
elif [[ -x "$(command -v /usr/local/bin/teeworlds-headless)" ]]
4144
then
42-
/usr/local/bin/teeworlds-headless "$clcfg" "$logdir/client.txt"
45+
/usr/local/bin/teeworlds-headless "$clcfg"
4346
tw_cl_bin=/usr/local/bin/teeworlds-headless
4447
elif [[ -x "$(command -v teeworlds)" ]]
4548
then
@@ -52,6 +55,22 @@ function connect_tw_client() {
5255
tw_client_running=1
5356
}
5457

58+
function connect_ddnet7_client() {
59+
if [[ -x "$(command -v DDNet7-headless)" ]]
60+
then
61+
DDNet7-headless "$clcfg"
62+
tw_cl_bin=DDNet7-headless
63+
elif [[ -x "$(command -v /usr/local/bin/DDNet7-headless)" ]]
64+
then
65+
/usr/local/bin/DDNet7-headless "$clcfg"
66+
tw_cl_bin=/usr/local/bin/DDNet7-headless
67+
else
68+
echo "Error: please install a DDNet7-headless"
69+
exit 1
70+
fi
71+
tw_client_running=1
72+
}
73+
5574
function get_test_names() {
5675
(find client -name "*.rb";find server -name "*.rb") | tr '\n' ' '
5776
}
@@ -94,7 +113,7 @@ function cleanup() {
94113
echo "[*] shutting down client ..."
95114
pkill -f "$tw_cl_bin $clcfg"
96115
fi
97-
[[ "$_timout_pid" != "" ]] && kill "$_timout_pid" &> /dev/null
116+
[[ "$_timeout_pid" != "" ]] && kill "$_timeout_pid" &> /dev/null
98117
}
99118

100119
trap cleanup EXIT
@@ -108,10 +127,18 @@ function fail() {
108127
# maybe a sleep does as well
109128
# or I still did not get flushing
110129
tail "$ruby_logfile" &>/dev/null
111-
echo "[-] end of ruby client log:"
112-
tail "$ruby_logfile"
113-
echo "[-] end of server log:"
114-
tail "$logdir/server.txt"
130+
if [[ "$testname" =~ ^client/ ]]
131+
then
132+
echo "[-] end of ruby client log:"
133+
tail "$ruby_logfile"
134+
echo "[-] end of server log:"
135+
tail "$logdir/server.txt"
136+
else
137+
echo "[-] end of ruby server log:"
138+
tail "$ruby_logfile"
139+
echo "[-] end of client log:"
140+
tail "$logdir/client.txt"
141+
fi
115142
echo "$msg"
116143
exit 1
117144
}
@@ -133,13 +160,21 @@ then
133160
echo "server log $(date)" > "$logdir/server.txt"
134161
start_tw_server
135162
else
136-
echo "client log $(date)" > "$logdir/client.txt"
137-
echo "server log $(date)" > "$ruby_logfile"
138-
connect_tw_client
163+
echo "ruby server log $(date)" > "$ruby_logfile"
164+
fi
165+
timeout 6 killme &
166+
_timeout_pid=$!
167+
if ! ruby "$testname" killme &> "$ruby_logfile"
168+
then
169+
fail "test $testname finished with non zero exit code"
170+
fi
171+
172+
if [[ "$testname" =~ ^server/ ]]
173+
then
174+
connect_ddnet7_client &> "$logdir/client.txt" &
175+
sleep 1
176+
echo "connect 127.0.0.1" > "$cl_fifo"
139177
fi
140-
timeout 3 killme &
141-
_timout_pid=$!
142-
ruby "$testname" killme &> "$ruby_logfile"
143178

144179
if [ "$testname" == "client/chat.rb" ]
145180
then
@@ -196,14 +231,19 @@ then
196231
then
197232
fail "Error: 'block 1' found after 'block 2' in client log"
198233
fi
234+
elif [ "$testname" == "server/connect.rb" ]
235+
then
236+
echo "rcon test" > "$cl_fifo"
237+
sleep 1
238+
echo "shutdown" > "$cl_fifo"
199239
else
200240
echo "Error: unkown test '$testname'"
201241
exit 1
202242
fi
203243

204244
if [ -f timeout.txt ]
205245
then
206-
echo "[-] Error timouted"
246+
echo "[-] Error timeouted"
207247
exit 1
208248
fi
209249

0 commit comments

Comments
 (0)