Skip to content

Commit

Permalink
Merge pull request #1101 from ai16z/fix/smokeTests
Browse files Browse the repository at this point in the history
feat: Smoke Test script
  • Loading branch information
shakkernerd authored Dec 14, 2024
2 parents e3d6feb + 5ffbd4d commit 82b475f
Showing 1 changed file with 23 additions and 17 deletions.
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

0 comments on commit 82b475f

Please sign in to comment.