Skip to content

Commit

Permalink
refactor: adjust smoke tests to make them more robust in GHA (#318)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
Signed-off-by: Atanas Atanasov <[email protected]>
Co-authored-by: Atanas Atanasov <[email protected]>
  • Loading branch information
mattp-swirldslabs and ata-nas authored Nov 7, 2024
1 parent b143a45 commit a6ecd97
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ jobs:
run: ./smoke-test.sh

- name: Stop Smoke Tests Container
if: always()
run: docker compose -p block-node stop

- name: Print Server Container Logs
if: always()
run: docker logs block-node-server
4 changes: 2 additions & 2 deletions server/docker/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ if [[ $# -lt 1 ]]; then
exit 1
fi

VERSION=${1}
VERSION=$1

echo "CREATING CONTAINER FOR VERSION ${VERSION}"
echo "Using project directory: ${2}"
echo

# run docker build
echo "Building container:"
docker buildx build --load -t "block-node-server:${1}" --build-context distributions=../build/distributions --build-arg VERSION="${VERSION}" . || exit "${?}"
docker buildx build --load -t "block-node-server:${VERSION}" --build-context distributions=../build/distributions --build-arg VERSION="${VERSION}" . || exit "${?}"
1 change: 1 addition & 0 deletions server/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3.8'

services:
block-node-server:
container_name: block-node-server
image: block-node-server:${VERSION}
env_file:
- .env
Expand Down
52 changes: 18 additions & 34 deletions server/src/test/resources/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Variable to track whether shutdown has been called
SHUTDOWN_CALLED=0

# Function to shut down the background processes
shutdown() {
if [[ $SHUTDOWN_CALLED -eq 1 ]]; then
Expand Down Expand Up @@ -42,20 +41,24 @@ shutdown() {
# Trap any exit signal to ensure everything is cleaned up
trap "shutdown; exit 1" ERR SIGINT SIGTERM

# 1. Verify that the logs have the startup pattern (only if log file is provided)
LOG_FILE=$1
STARTUP_PATTERN="Block Node Server started at port"
# 1. Call the endpoints /health/livez and /health/readyz
SERVER_URL="http://localhost:8080"
LIVENESS_ENDPOINT="/healthz/livez"
READINESS_ENDPOINT="/healthz/readyz"

if [[ -n "$LOG_FILE" ]]; then
if grep -q "$STARTUP_PATTERN" "$LOG_FILE"; then
echo "Startup pattern found in logs."
else
echo "Startup pattern not found in logs."
exit 1
fi
else
echo "No log file provided, skipping startup pattern check."
if ! curl -v --connect-timeout 5 --max-time 10 --retry 12 --retry-delay 5 --retry-max-time 100 --retry-all-errors $SERVER_URL$LIVENESS_ENDPOINT; then
echo "$LIVENESS_ENDPOINT failed."
shutdown
exit 1
fi
echo "$LIVENESS_ENDPOINT endpoint is healthy."

if ! curl -v --connect-timeout 5 --max-time 10 --retry 12 --retry-delay 5 --retry-max-time 100 --retry-all-errors $SERVER_URL$READINESS_ENDPOINT; then
echo "$READINESS_ENDPOINT endpoint failed."
shutdown
exit 1
fi
echo "$READINESS_ENDPOINT endpoint is ready."

# 2. Start the consumer script with parameters 1 1000 and save logs to consumer.log
./consumer.sh 1 1000 > consumer.log 2>&1 &
Expand All @@ -67,10 +70,10 @@ echo "Started consumer with PID $CONSUMER_PID, logging to consumer.log"
PRODUCER_PID=$!
echo "Started producer with PID $PRODUCER_PID, logging to producer.log"

# Sleep time after starting the consumer
# 4. Sleep time after starting the consumer and producer scripts
sleep 5 # Adjust sleep time as needed

# 4. Run the get-block script with parameter 1 and save logs to get-block.log
# 5. Run the get-block script with parameter 1 and save logs to get-block.log
if ! ./get-block.sh 1 > get-block.log 2>&1; then
echo "get-block.sh failed."
echo "get-block logs:"
Expand All @@ -80,25 +83,6 @@ if ! ./get-block.sh 1 > get-block.log 2>&1; then
fi
echo "get-block.sh executed successfully."

# 5. Call the endpoints /health/livez and /health/readyz
SERVER_URL="http://localhost:8080"
LIVENESS_ENDPOINT="/healthz/livez"
READINESS_ENDPOINT="/healthz/readyz"

if ! curl -f $SERVER_URL$LIVENESS_ENDPOINT; then
echo "$LIVENESS_ENDPOINT failed."
shutdown
exit 1
fi
echo "$LIVENESS_ENDPOINT endpoint is healthy."

if ! curl -f $SERVER_URL$READINESS_ENDPOINT; then
echo "$READINESS_ENDPOINT endpoint failed."
shutdown
exit 1
fi
echo "$READINESS_ENDPOINT endpoint is ready."

# 6. Shut everything down
shutdown

Expand Down

0 comments on commit a6ecd97

Please sign in to comment.