fix(ci): support macOS by using gtimeout from coreutils

This commit is contained in:
m1ngsama 2026-02-07 14:43:46 +08:00
parent bd4695b329
commit c120cb5ac5
5 changed files with 34 additions and 10 deletions

View file

@ -25,7 +25,7 @@ jobs:
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install libssh
brew install libssh coreutils
- name: Build
run: make

View file

@ -20,12 +20,18 @@ cleanup() {
}
trap cleanup EXIT
# Detect timeout command
TIMEOUT_CMD="timeout"
if command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_CMD="gtimeout"
fi
echo "Testing anonymous SSH access to TNT server..."
echo ""
# Test 1: Connection with any username and password
echo "Test 1: Connection with any username (should succeed)"
timeout 10 expect -c "
$TIMEOUT_CMD 10 expect -c "
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT testuser@localhost
expect {
\"password:\" {
@ -54,7 +60,7 @@ echo ""
# Test 2: Connection should work with empty password
echo "Test 2: Simple connection (standard SSH command)"
timeout 10 expect -c "
$TIMEOUT_CMD 10 expect -c "
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT anonymous@localhost
expect {
\"password:\" {

View file

@ -13,6 +13,12 @@ cleanup() {
trap cleanup EXIT
# Detect timeout command
TIMEOUT_CMD="timeout"
if command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_CMD="gtimeout"
fi
echo "=== TNT Basic Tests ==="
# Path to binary
@ -39,7 +45,7 @@ else
fi
# Test 2: SSH connection
if timeout 5 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
if $TIMEOUT_CMD 5 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-o BatchMode=yes -p $PORT localhost exit 2>/dev/null; then
echo "✓ SSH connection works"
PASS=$((PASS + 1))
@ -49,7 +55,7 @@ else
fi
# Test 3: Message logging
(echo "testuser"; echo "test message"; sleep 1) | timeout 5 ssh -o StrictHostKeyChecking=no \
(echo "testuser"; echo "test message"; sleep 1) | $TIMEOUT_CMD 5 ssh -o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null -p $PORT localhost >/dev/null 2>&1 &
sleep 3
if [ -f messages.log ]; then

View file

@ -43,6 +43,12 @@ if [ ! -f "$BIN" ]; then
exit 1
fi
# Detect timeout command
TIMEOUT_CMD="timeout"
if command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_CMD="gtimeout"
fi
# Test 1: 4096-bit RSA Key Generation
print_test "1. RSA 4096-bit Key Generation"
rm -f host_key
@ -75,19 +81,19 @@ fi
print_test "2. Environment Variable Configuration"
# Test bind address
TNT_BIND_ADDR=127.0.0.1 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \
TNT_BIND_ADDR=127.0.0.1 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \
pass "TNT_BIND_ADDR configuration works" || fail "TNT_BIND_ADDR not working"
# Test with access token set (just verify it starts)
TNT_ACCESS_TOKEN="test123" timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \
TNT_ACCESS_TOKEN="test123" $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \
pass "TNT_ACCESS_TOKEN configuration accepted" || fail "TNT_ACCESS_TOKEN not working"
# Test max connections configuration
TNT_MAX_CONNECTIONS=10 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \
TNT_MAX_CONNECTIONS=10 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \
pass "TNT_MAX_CONNECTIONS configuration accepted" || fail "TNT_MAX_CONNECTIONS not working"
# Test rate limit toggle
TNT_RATE_LIMIT=0 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \
TNT_RATE_LIMIT=0 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \
pass "TNT_RATE_LIMIT configuration accepted" || fail "TNT_RATE_LIMIT not working"
sleep 1

View file

@ -12,6 +12,12 @@ if [ ! -f "$BIN" ]; then
exit 1
fi
# Detect timeout command
TIMEOUT_CMD="timeout"
if command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_CMD="gtimeout"
fi
echo "Starting TNT server on port $PORT..."
$BIN -p $PORT &
SERVER_PID=$!
@ -27,7 +33,7 @@ echo "Spawning $CLIENTS clients for ${DURATION}s..."
for i in $(seq 1 $CLIENTS); do
(
sleep $((i % 5))
echo "test user $i" | timeout $DURATION ssh -o StrictHostKeyChecking=no \
echo "test user $i" | $TIMEOUT_CMD $DURATION ssh -o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null -p $PORT localhost \
>/dev/null 2>&1
) &