From 96a29c94294213b4268a508de47934e3604a5c0c Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Tue, 23 Jan 2024 22:00:31 +0800 Subject: [PATCH] Test server chat in CI (#13) --- .github/workflows/integration.yml | 3 +++ integration_test/run.sh | 22 +++++++++++++++++++--- integration_test/server/chat.rb | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100755 integration_test/server/chat.rb diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index d4c053b..95ae28f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -58,3 +58,6 @@ jobs: - name: '[SERVER] Test connect' run: | ./integration_test/run.sh server/connect.rb + - name: '[SERVER] Test chat' + run: | + ./integration_test/run.sh server/chat.rb diff --git a/integration_test/run.sh b/integration_test/run.sh index 2fed5fd..bcc5538 100755 --- a/integration_test/run.sh +++ b/integration_test/run.sh @@ -154,7 +154,7 @@ fail() { echo "[-] end of ruby server log:" tail -n 10 "$ruby_logfile" echo "[-] end of client log:" - cat "$logdir/client.txt" + tail -n 10 "$logdir/client.txt" fi if [ ! -s "$ruby_logfile_err" ] then @@ -228,7 +228,7 @@ assert_in_log() { local needle="$1" local logfile_path="$2" local num_matches="$3" - if ! grep -q "$needle" "$logfile_path" + if ! grep -qF "$needle" "$logfile_path" then echo "[-] Error: did not find expected string in logs" echo "[-]" @@ -240,7 +240,7 @@ assert_in_log() { if [ "$num_matches" != "" ] then local actual_matches - actual_matches="$(grep -c "$needle" "$logfile_path")" + actual_matches="$(grep -cF "$needle" "$logfile_path")" if [ "$actual_matches" != "$num_matches" ] then echo "[-] Error: found string unexpected amount of times in log file" @@ -324,6 +324,22 @@ then assert_in_log "'test_client' joined the game" "$ruby_logfile" 1 assert_in_log "rcon='shutdown'" "$ruby_logfile" 1 +elif [ "$testname" == "server/chat.rb" ] +then + fifo "say hello gamers" "$cl_fifo" + sleep 1 + fifo "say uwu" "$cl_fifo" + sleep 1 + fifo "rcon_auth test" "$cl_fifo" + sleep 1 + fifo "rcon shutdown" "$cl_fifo" + sleep 1 + fifo "quit" "$cl_fifo" + # ddnet quitting can get stuck so send a kill to ensure it dies + kill "$_client_pid" + + assert_in_log "hello gamers" "$ruby_logfile" 1 + assert_in_log "[testchat] test_client: uwu" "$ruby_logfile" 1 else echo "Error: unkown test '$testname'" exit 1 diff --git a/integration_test/server/chat.rb b/integration_test/server/chat.rb new file mode 100755 index 0000000..00c7131 --- /dev/null +++ b/integration_test/server/chat.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require_relative '../../lib/teeworlds_server' + +server = TeeworldsServer.new(verbose: false) + +server.on_chat do |context, chat_msg| + context.cancel + + puts "[testchat] #{chat_msg.author.name}: #{chat_msg.message}" +end + +server.run('127.0.0.1', 8377)