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

chore: improve smokeTests environment validation and logging #1046

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 29 additions & 23 deletions scripts/smokeTests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/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:"
Expand Down Expand Up @@ -27,60 +30,63 @@ if (( CURRENT_NODE_VERSION < REQUIRED_NODE_VERSION )); then
fi

# Autodetect project directory relative to this script's path
PROJECT_DIR="$0"
while [ -h "$PROJECT_DIR" ]; do
ls=$(ls -ld "$PROJECT_DIR")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' > /dev/null; then
PROJECT_DIR="$link"
else
PROJECT_DIR="$(dirname "$PROJECT_DIR")/$link"
fi
done
PROJECT_DIR="$(dirname "$PROJECT_DIR")/.."
PROJECT_DIR="$(cd "$PROJECT_DIR"; pwd)"
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above code can deal with symbolic links, I've been using this template for years in my scripts.


cd $PROJECT_DIR
cd "$PROJECT_DIR"

cp .env.example .env

pnpm install -r

pnpm build

# Create temp file and ensure cleanup
OUTFILE="$(mktemp)"
echo $OUTFILE
trap 'rm -f "$OUTFILE"' EXIT
echo "Using temporary output file: $OUTFILE"

# Add timeout configuration
TIMEOUT=30
INTERVAL=0.5
TIMER=0

(
# Wait for the ready message
# Wait for the ready message with timeout
while true; do
Copy link
Contributor

@jzvikart jzvikart Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we shouldn't be using sleep here. We should fix whatever underlying problem is causing the test to fail without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - arbitrary sleeps can make tests both slower than necessary and introduce flakiness in my experience. I can create an issue/brainstorm a better termination signal instead

if [[ $TIMER -ge $TIMEOUT ]]; then
echo "Error: Timeout waiting for application to start after $TIMEOUT seconds"
kill $$
exit 1
fi

if grep -q "Chat started" "$OUTFILE"; then
echo "exit"; sleep 2
break
fi
sleep 0.5

sleep $INTERVAL
TIMER=$(echo "$TIMER + $INTERVAL" | bc)
done
) | pnpm start --character=characters/trump.character.json > "$OUTFILE" &

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

echo "----- OUTPUT START -----"
cat "$OUTFILE"
echo "----- OUTPUT END -----"

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

# Check if output.txt contains "Terminating and cleaning up resources..."
# Check if output contains expected termination message
if grep -q "Terminating and cleaning up resources..." "$OUTFILE"; then
echo "Script completed successfully."
else
echo "Error: The output does not contain the expected string."
echo "Error: The output does not contain the expected termination message."
exit 1
fi

# Clean up
rm "$OUTFILE"
fi
Loading