| 1 | #!/usr/bin/env bash |
| 2 | # Run each smoke Worker under `celld dev` and fail if its report isn't ok. |
| 3 | # A Worker's paths.txt adds requests: "PATH<TAB>TEXT" lines, each passing when |
| 4 | # GET PATH answers 200 with TEXT in its body. |
| 5 | # homeflare/smoke/run.sh [path/to/celld] |
| 6 | # Defaults to target/debug/celld. Needs esbuild on PATH (celld bundles with it). |
| 7 | set -euo pipefail |
| 8 | |
| 9 | SMOKE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | REPO_DIR="$(cd "$SMOKE_DIR/../.." && pwd)" |
| 11 | CELLD="${1:-$REPO_DIR/target/debug/celld}" |
| 12 | CELLD="$(cd "$(dirname "$CELLD")" && pwd)/$(basename "$CELLD")" |
| 13 | PORT="${SMOKE_PORT:-9876}" |
| 14 | |
| 15 | [ -x "$CELLD" ] || { echo "no celld at $CELLD" >&2; exit 1; } |
| 16 | |
| 17 | status=0 |
| 18 | for worker in "$SMOKE_DIR"/*/; do |
| 19 | name="$(basename "$worker")" |
| 20 | log="$(mktemp)" |
| 21 | (cd "$worker" && NO_COLOR=1 exec "$CELLD" dev --clean --port "$PORT") >"$log" 2>&1 & |
| 22 | pid=$! |
| 23 | report="" |
| 24 | for _ in $(seq 1 120); do |
| 25 | report="$(curl -sS "http://127.0.0.1:$PORT/${SMOKE_QUERY:-}" 2>/dev/null || true)" |
| 26 | [ -n "$report" ] && break |
| 27 | kill -0 "$pid" 2>/dev/null || break |
| 28 | sleep 0.5 |
| 29 | done |
| 30 | extra="" |
| 31 | if [ -f "$worker/paths.txt" ]; then |
| 32 | while IFS=$'\t' read -r path want; do |
| 33 | [ -n "$path" ] || continue |
| 34 | got="$(curl -sS -w '\n%{http_code}' "http://127.0.0.1:$PORT$path" 2>&1 || true)" |
| 35 | code="${got##*$'\n'}"; body="${got%$'\n'*}" |
| 36 | if [ "$code" != 200 ] || [[ "$body" != *"$want"* ]]; then |
| 37 | extra+="GET $path: $code $body"$'\n' |
| 38 | fi |
| 39 | done < "$worker/paths.txt" |
| 40 | fi |
| 41 | kill "$pid" 2>/dev/null || true |
| 42 | wait "$pid" 2>/dev/null || true |
| 43 | rm -rf "$worker/.celld" |
| 44 | if printf '%s' "$report" | grep -q '"ok":true' && [ -z "$extra" ]; then |
| 45 | echo "ok $name" |
| 46 | else |
| 47 | echo "FAIL $name" |
| 48 | if [ -n "$report" ]; then printf '%s\n' "$report"; else cat "$log"; fi |
| 49 | printf '%s' "$extra" |
| 50 | status=1 |
| 51 | fi |
| 52 | rm -f "$log" |
| 53 | done |
| 54 | exit "$status" |