Refactor SSH command in run-tests.sh to handle MUD connection closure gracefully
Some checks failed
Smoke tests / Build and smoke test (push) Failing after 34s
Some checks failed
Smoke tests / Build and smoke test (push) Failing after 34s
- Introduced a new function `ssh_mud` to encapsulate SSH command execution and treat exit code 255 as a success. - Updated all SSH calls in the test script to use the new function for improved error handling.
This commit is contained in:
19
run-tests.sh
19
run-tests.sh
@@ -4,6 +4,13 @@ set -e
|
|||||||
TEST_DB=${MUD_TEST_DB:-./mudserver.db.test}
|
TEST_DB=${MUD_TEST_DB:-./mudserver.db.test}
|
||||||
SERVER_PID=
|
SERVER_PID=
|
||||||
|
|
||||||
|
# SSH returns 255 when MUD closes connection after quit — treat as success
|
||||||
|
ssh_mud() {
|
||||||
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 "$@"
|
||||||
|
r=$?
|
||||||
|
[[ $r -eq 0 || $r -eq 255 ]] || exit 1
|
||||||
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [ -n "${SERVER_PID:-}" ]; then
|
if [ -n "${SERVER_PID:-}" ]; then
|
||||||
kill $SERVER_PID 2>/dev/null || true
|
kill $SERVER_PID 2>/dev/null || true
|
||||||
@@ -17,7 +24,7 @@ SERVER_PID=$!
|
|||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# Test 1: New player creation + basic commands
|
# Test 1: New player creation + basic commands
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
|
ssh_mud smoketest@localhost <<'EOF'
|
||||||
1
|
1
|
||||||
1
|
1
|
||||||
look
|
look
|
||||||
@@ -33,7 +40,7 @@ quit
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Test 2: Persistence - reconnect
|
# Test 2: Persistence - reconnect
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
|
ssh_mud smoketest@localhost <<'EOF'
|
||||||
look
|
look
|
||||||
stats
|
stats
|
||||||
quit
|
quit
|
||||||
@@ -47,7 +54,7 @@ EOF
|
|||||||
./target/debug/mudtool -d "$TEST_DB" settings list
|
./target/debug/mudtool -d "$TEST_DB" settings list
|
||||||
|
|
||||||
# Test 4: Admin commands in-game
|
# Test 4: Admin commands in-game
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
|
ssh_mud smoketest@localhost <<'EOF'
|
||||||
admin help
|
admin help
|
||||||
admin list
|
admin list
|
||||||
admin registration on
|
admin registration on
|
||||||
@@ -57,14 +64,14 @@ EOF
|
|||||||
|
|
||||||
# Test 5: Registration gate
|
# Test 5: Registration gate
|
||||||
./target/debug/mudtool -d "$TEST_DB" settings set registration_open false
|
./target/debug/mudtool -d "$TEST_DB" settings set registration_open false
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 newplayer@localhost <<'EOF'
|
ssh_mud newplayer@localhost <<'EOF'
|
||||||
quit
|
quit
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Test 6: Tick-based combat (connect and wait for ticks)
|
# Test 6: Tick-based combat (connect and wait for ticks)
|
||||||
./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
|
./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
|
||||||
./target/debug/mudtool -d "$TEST_DB" players delete smoketest
|
./target/debug/mudtool -d "$TEST_DB" players delete smoketest
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
|
ssh_mud smoketest@localhost <<'EOF'
|
||||||
1
|
1
|
||||||
1
|
1
|
||||||
go south
|
go south
|
||||||
@@ -72,7 +79,7 @@ go south
|
|||||||
attack thief
|
attack thief
|
||||||
EOF
|
EOF
|
||||||
sleep 8
|
sleep 8
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
|
ssh_mud smoketest@localhost <<'EOF'
|
||||||
stats
|
stats
|
||||||
quit
|
quit
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user