|
| 1 | +#!/bin/bash |
| 2 | +# CI smoke test for the API Boundary Node recovery container. |
| 3 | +# Builds the image, starts it, waits for readiness, and verifies |
| 4 | +# that a canister query through it succeeds. |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +CONTAINER_NAME="api-bn-test-$$" |
| 9 | +IMAGE_NAME="api-boundary-node" |
| 10 | +IMAGE_TAG="test" |
| 11 | +MAX_WAIT=300 # 5 minutes for registry sync + replica discovery |
| 12 | + |
| 13 | +cleanup() { |
| 14 | + echo "Cleaning up..." |
| 15 | + docker rm -f "$CONTAINER_NAME" 2>/dev/null || true |
| 16 | +} |
| 17 | +trap cleanup EXIT |
| 18 | + |
| 19 | +# ─── Pre-check: stop anything already on port 8080 ─── |
| 20 | +if curl -sf http://localhost:8080/api/v2/status -o /dev/null 2>/dev/null; then |
| 21 | + echo "ERROR: Something is already listening on port 8080." |
| 22 | + echo "Stop any existing api-bn containers first: docker rm -f api-bn" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# ─── Build ─── |
| 27 | +echo "=== Building image ===" |
| 28 | +IMAGE_NAME="$IMAGE_NAME" IMAGE_TAG="$IMAGE_TAG" "${SCRIPT_DIR}/build.sh" |
| 29 | + |
| 30 | +# ─── Run ─── |
| 31 | +echo "=== Starting container ===" |
| 32 | +docker run -d --name "$CONTAINER_NAME" --network host "${IMAGE_NAME}:${IMAGE_TAG}" |
| 33 | + |
| 34 | +# ─── Wait for readiness ─── |
| 35 | +echo "=== Waiting for boundary node to become ready (up to ${MAX_WAIT}s) ===" |
| 36 | +WAITED=0 |
| 37 | +while true; do |
| 38 | + # Check container is still running |
| 39 | + if ! docker inspect --format='{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null | grep -q true; then |
| 40 | + echo "FAIL: Container exited unexpectedly." |
| 41 | + docker logs "$CONTAINER_NAME" 2>&1 | tail -30 |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | + # Check if the boundary node is healthy via the Prometheus metric |
| 46 | + if curl -sf http://localhost:9090/metrics 2>/dev/null | grep -q 'ic_boundary_healthy 1'; then |
| 47 | + echo "Boundary node is healthy after ${WAITED}s." |
| 48 | + break |
| 49 | + fi |
| 50 | + |
| 51 | + if [ "$WAITED" -ge "$MAX_WAIT" ]; then |
| 52 | + echo "FAIL: Boundary node did not become healthy within ${MAX_WAIT}s." |
| 53 | + docker logs "$CONTAINER_NAME" 2>&1 | tail -30 |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + |
| 57 | + sleep 5 |
| 58 | + WAITED=$((WAITED + 5)) |
| 59 | + if [ $((WAITED % 30)) -eq 0 ]; then |
| 60 | + echo " Still waiting... (${WAITED}s)" |
| 61 | + fi |
| 62 | +done |
| 63 | + |
| 64 | +# ─── Test canister query ─── |
| 65 | +echo "=== Testing canister query ===" |
| 66 | +RESULT=$(dfx canister --network http://localhost:8080 call ryjl3-tyaaa-aaaaa-aaaba-cai name --query 2>&1) |
| 67 | + |
| 68 | +if echo "$RESULT" | grep -q "Internet Computer"; then |
| 69 | + echo "PASS: $RESULT" |
| 70 | + exit 0 |
| 71 | +else |
| 72 | + echo "FAIL: Unexpected response: $RESULT" |
| 73 | + exit 1 |
| 74 | +fi |
0 commit comments