-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathsmokeTests.sh
executable file
·100 lines (74 loc) · 2.41 KB
/
smokeTests.sh
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
96
97
98
99
100
#!/bin/bash
# Strict mode, exit on error, undefined variables, and pipe failures
set -euo pipefail
# Print some information about the environment to aid in case of troubleshooting
echo "node version:"
node --version
echo "python version:"
python3 --version
echo "make version:"
make --version
echo "gcc version:"
gcc --version
echo "g++ version:"
g++ --version
# Check Node.js version
REQUIRED_NODE_VERSION=23
CURRENT_NODE_VERSION=$(node -v | cut -d'.' -f1 | sed 's/v//')
if (( CURRENT_NODE_VERSION < REQUIRED_NODE_VERSION )); then
echo "Error: Node.js version must be $REQUIRED_NODE_VERSION or higher. Current version is $CURRENT_NODE_VERSION."
exit 1
fi
# Autodetect project directory relative to this script's path
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_DIR"
cp .env.example .env
pnpm install -r --frozen-lockfile
pnpm build
# Create temp file and ensure cleanup
OUTFILE="$(mktemp)"
trap 'rm -f "$OUTFILE"' EXIT
echo "Using temporary output file: $OUTFILE"
# Add timeout configuration
TIMEOUT=300 # 30 seconds represented as 1800 tenths of a second
INTERVAL=5 # Represent 0.5 seconds as 5 tenths of a second
TIMER=0
# Start the application and capture logs in the background
pnpm start --character=characters/trump.character.json > "$OUTFILE" 2>&1 &
APP_PID=$! # Capture the PID of the background process
(
# Wait for the ready message with timeout
while true; do
if (( TIMER >= TIMEOUT )); then
>&2 echo "ERROR: Timeout waiting for application to start after $((TIMEOUT / 10)) seconds"
kill $APP_PID # Terminate the pnpm process
exit 1
fi
if grep -q "REST API bound to 0.0.0.0" "$OUTFILE"; then
>&2 echo "SUCCESS: Direct Client API is ready! Proceeding..."
break
fi
sleep 0.5
TIMER=$((TIMER + INTERVAL))
done
)
# Gracefully terminate the application if needed
kill $APP_PID
wait $APP_PID 2>/dev/null || true # Ensure the process is cleaned up
RESULT=$?
# Output logs
echo "----- OUTPUT START -----"
cat "$OUTFILE"
echo "----- OUTPUT END -----"
# Check the application exit code
if [[ $RESULT -ne 0 ]]; then
echo "Error: 'pnpm start' command exited with an error (code: $RESULT)"
exit 1
fi
# Final validation
if grep -q "Server closed successfully" "$OUTFILE"; then
echo "Smoke Test completed successfully."
else
echo "Error: The output does not contain the expected termination message."
exit 1
fi