interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

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
7set -euo pipefail
8
9PORT="${1:-18080}"
10ENGINE_DIR="$(cd "$(dirname "$0")" && pwd)"
11ENGINE_BIN="${ENGINE_DIR}/mojo_engine"
12TIMEOUT=10
13
14# ── 1. Build ────────────────────────────────────────────────────────────
15echo "[test] Building mojo_engine ..."
16make -C "$ENGINE_DIR" clean && make -C "$ENGINE_DIR"
17echo "[test] Build succeeded."
18
19# ── 2. Start engine in background ──────────────────────────────────────
20echo "[test] Starting mojo_engine on port ${PORT} ..."
21"$ENGINE_BIN" --model /dev/null --port "$PORT" --threads 2 &
22ENGINE_PID=$!
23
24# Ensure we kill the engine on exit (even on failure)
25cleanup() {
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}
30trap cleanup EXIT
31
32# ── 3. Wait for readiness (poll /health with curl) ─────────────────────
33echo "[test] Waiting up to ${TIMEOUT}s for /health ..."
34elapsed=0
35while [ "$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))
42done
43
44if [ "$elapsed" -ge "$TIMEOUT" ]; then
45 echo "[FAIL] Engine did not respond within ${TIMEOUT}s."
46 exit 1
47fi
48
49# ── 4. Verify response body ────────────────────────────────────────────
50RESPONSE=$(curl -sf --max-time 5 "http://127.0.0.1:${PORT}/health")
51echo "[test] Response: ${RESPONSE}"
52
53if echo "$RESPONSE" | grep -q '"status"'; then
54 echo "[PASS] /health returned expected JSON."
55else
56 echo "[FAIL] /health response missing expected key."
57 exit 1
58fi
59
60echo "[test] All checks passed."
61exit 0