-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Changes from 3 commits
8264094
67dc5c8
7cd3bf2
92316b6
9f39f4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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:" | ||
|
@@ -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)" | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.