Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/engine/test_health.sh # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / engine / test_health.sh` 61 lines · 2426 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # ── test_health.sh — Verify mojo_engine starts and responds to /health ── 3 # Usage: ./test_health.sh [port] 4 # port defaults to 18080 (alt port to avoid conflicts) 5 # ───────────────────────────────────────────────────────────────────────── 6 7 set -euo pipefail 8 9 PORT="${1:-18080}" 10 ENGINE_DIR="$(cd "$(dirname "$0")" && pwd)" 11 ENGINE_BIN="${ENGINE_DIR}/mojo_engine" 12 TIMEOUT=10 13 14 # ── 1. Build ──────────────────────────────────────────────────────────── 15 echo "[test] Building mojo_engine ..." 16 make -C "$ENGINE_DIR" clean && make -C "$ENGINE_DIR" 17 echo "[test] Build succeeded." 18 19 # ── 2. Start engine in background ────────────────────────────────────── 20 echo "[test] Starting mojo_engine on port ${PORT} ..." 21 "$ENGINE_BIN" --model /dev/null --port "$PORT" --threads 2 & 22 ENGINE_PID=$! 23 24 # Ensure we kill the engine on exit (even on failure) 25 cleanup() { 26 echo "[test] Stopping engine (PID ${ENGINE_PID}) ..." 27 kill "$ENGINE_PID" 2>/dev/null || true 28 wait "$ENGINE_PID" 2>/dev/null || true 29 } 30 trap cleanup EXIT 31 32 # ── 3. Wait for readiness (poll /health with curl) ───────────────────── 33 echo "[test] Waiting up to ${TIMEOUT}s for /health ..." 34 elapsed=0 35 while [ "$elapsed" -lt "$TIMEOUT" ]; do 36 if curl -sf --max-time 2 "http://127.0.0.1:${PORT}/health" >/dev/null 2>&1; then 37 echo "[test] /health responded, engine is ready." 38 break 39 fi 40 sleep 1 41 elapsed=$((elapsed + 1)) 42 done 43 44 if [ "$elapsed" -ge "$TIMEOUT" ]; then 45 echo "[FAIL] Engine did not respond within ${TIMEOUT}s." 46 exit 1 47 fi 48 49 # ── 4. Verify response body ──────────────────────────────────────────── 50 RESPONSE=$(curl -sf --max-time 5 "http://127.0.0.1:${PORT}/health") 51 echo "[test] Response: ${RESPONSE}" 52 53 if echo "$RESPONSE" | grep -q '"status"'; then 54 echo "[PASS] /health returned expected JSON." 55 else 56 echo "[FAIL] /health response missing expected key." 57 exit 1 58 fi 59 60 echo "[test] All checks passed." 61 exit 0