Skip to content

Commit 5ffbd4d

Browse files
committed
feat: Smoke Test script
1 parent 9a0f5fe commit 5ffbd4d

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

scripts/smokeTests.sh

+23-17
Original file line numberDiff line numberDiff line change
@@ -46,48 +46,54 @@ trap 'rm -f "$OUTFILE"' EXIT
4646
echo "Using temporary output file: $OUTFILE"
4747

4848
# Add timeout configuration
49-
TIMEOUT=1800 # 3 minutes represented as 1800 tenths of a second
49+
TIMEOUT=300 # 30 seconds represented as 1800 tenths of a second
5050
INTERVAL=5 # Represent 0.5 seconds as 5 tenths of a second
5151
TIMER=0
5252

53+
# Start the application and capture logs in the background
54+
pnpm start --character=characters/trump.character.json > "$OUTFILE" 2>&1 &
55+
56+
APP_PID=$! # Capture the PID of the background process
57+
5358
(
5459
# Wait for the ready message with timeout
5560
while true; do
5661
if (( TIMER >= TIMEOUT )); then
57-
echo "Error: Timeout waiting for application to start after $((TIMEOUT / 10)) seconds"
58-
echo "Logs from $OUTFILE:"
59-
cat "$OUTFILE"
60-
pkill -f "pnpm start"
61-
exit 1
62+
>&2 echo "ERROR: Timeout waiting for application to start after $((TIMEOUT / 10)) seconds"
63+
kill $APP_PID # Terminate the pnpm process
64+
exit 1
6265
fi
6366

64-
if grep -q "Chat started" "$OUTFILE"; then
65-
echo "exit"; sleep 2
66-
break
67+
if grep -q "REST API bound to 0.0.0.0" "$OUTFILE"; then
68+
>&2 echo "SUCCESS: Direct Client API is ready! Proceeding..."
69+
break
6770
fi
6871

6972
sleep 0.5
7073
TIMER=$((TIMER + INTERVAL))
7174
done
72-
) | pnpm start --character=characters/trump.character.json > "$OUTFILE" &
75+
)
76+
77+
# Gracefully terminate the application if needed
78+
kill $APP_PID
79+
wait $APP_PID 2>/dev/null || true # Ensure the process is cleaned up
7380

74-
# Wait for process to finish
75-
wait $!
7681
RESULT=$?
7782

83+
# Output logs
7884
echo "----- OUTPUT START -----"
7985
cat "$OUTFILE"
8086
echo "----- OUTPUT END -----"
8187

82-
# Check the exit code of the last command
88+
# Check the application exit code
8389
if [[ $RESULT -ne 0 ]]; then
84-
echo "Error: 'start' command exited with an error (code: $RESULT)"
90+
echo "Error: 'pnpm start' command exited with an error (code: $RESULT)"
8591
exit 1
8692
fi
8793

88-
# Check if output contains expected termination message
89-
if grep -q "Terminating and cleaning up resources..." "$OUTFILE"; then
90-
echo "Script completed successfully."
94+
# Final validation
95+
if grep -q "Server closed successfully" "$OUTFILE"; then
96+
echo "Smoke Test completed successfully."
9197
else
9298
echo "Error: The output does not contain the expected termination message."
9399
exit 1

0 commit comments

Comments
 (0)