-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_test.sh
More file actions
executable file
·95 lines (82 loc) · 2.3 KB
/
run_test.sh
File metadata and controls
executable file
·95 lines (82 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
set -e
# Configuration
GATEWAY_PORT=8080
LOG_FILE="/tmp/zerox_test.log"
echo "=========================================="
echo " WebSocket Push Integration Test"
echo "=========================================="
cleanup() {
echo ""
echo "[Clean] Stopping services..."
# First try graceful shutdown with SIGTERM
pkill -TERM -f "zero_x_infinity" 2>/dev/null || true
sleep 1
# Then force kill if still running
pkill -9 -f "zero_x_infinity" 2>/dev/null || true
if lsof -i:$GATEWAY_PORT >/dev/null 2>&1; then
lsof -ti:$GATEWAY_PORT | xargs kill -9 >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
# 1. Check Dependencies
echo "[1] Checking Dependencies..."
if [ ! -f "scripts/check_deps.sh" ]; then
echo "❌ scripts/check_deps.sh not found!"
exit 1
fi
./scripts/check_deps.sh > /dev/null
echo "✅ Dependencies ready."
# 2. Start Service
echo "[2] Starting Gateway..."
nohup cargo run --release -- --gateway --port $GATEWAY_PORT > "$LOG_FILE" 2>&1 &
GATEWAY_PID=$!
echo " Gateway PID: $GATEWAY_PID"
echo " Logs: $LOG_FILE"
echo " Waiting for port $GATEWAY_PORT..."
MAX_RETRIES=30
COUNT=0
READY=false
while [ $COUNT -lt $MAX_RETRIES ]; do
if lsof -i:$GATEWAY_PORT >/dev/null; then
# Check if HTTP endpoint is responsive
if curl -s "http://localhost:$GATEWAY_PORT/api/v1/orders?user_id=1001" >/dev/null 2>&1; then
READY=true
break
fi
fi
sleep 1
((COUNT++))
printf "."
done
echo ""
if [ "$READY" = false ]; then
echo "❌ Gateway failed to start."
echo "--- Last 20 lines of log ---"
tail -n 20 "$LOG_FILE"
exit 1
fi
echo "✅ Gateway is UP and Listening."
# 3. Run Logic Test
echo "[3] Running Logic Test (Python)..."
# Ensure venv exists
if [ ! -d ".venv_test" ]; then
echo " Creating Python venv..."
python3 -m venv .venv_test
source .venv_test/bin/activate
pip install --quiet aiohttp websockets
else
source .venv_test/bin/activate
fi
python3 test_push_logic.py
TEST_EXIT_CODE=$?
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo ""
echo "🎉 ALL TESTS PASSED"
else
echo ""
echo "❌ TEST FAILED"
echo "--- Gateway Logs (Push Related) ---"
grep -E "PUSH|WsService|Settlement" "$LOG_FILE" | tail -n 20 || echo "(No push logs found)"
fi
exit $TEST_EXIT_CODE