Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Smoke Test script #1101

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions scripts/smokeTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,54 @@ trap 'rm -f "$OUTFILE"' EXIT
echo "Using temporary output file: $OUTFILE"

# Add timeout configuration
TIMEOUT=1800 # 3 minutes represented as 1800 tenths of a second
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
echo "Error: Timeout waiting for application to start after $((TIMEOUT / 10)) seconds"
echo "Logs from $OUTFILE:"
cat "$OUTFILE"
pkill -f "pnpm start"
exit 1
>&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 "Chat started" "$OUTFILE"; then
echo "exit"; sleep 2
break
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
) | pnpm start --character=characters/trump.character.json > "$OUTFILE" &
)

# Gracefully terminate the application if needed
kill $APP_PID
wait $APP_PID 2>/dev/null || true # Ensure the process is cleaned up

# Wait for process to finish
wait $!
RESULT=$?

# Output logs
echo "----- OUTPUT START -----"
cat "$OUTFILE"
echo "----- OUTPUT END -----"

# Check the exit code of the last command
# Check the application exit code
if [[ $RESULT -ne 0 ]]; then
echo "Error: 'start' command exited with an error (code: $RESULT)"
echo "Error: 'pnpm start' command exited with an error (code: $RESULT)"
exit 1
fi

# Check if output contains expected termination message
if grep -q "Terminating and cleaning up resources..." "$OUTFILE"; then
echo "Script completed successfully."
# 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
Expand Down
Loading