search for standard sites
pub-search.waow.tech
search
zig
blog
atproto
2.3 kB
62 lines
1#!/bin/sh
2# Production smoke test — THE definition of "prod is healthy".
3#
4# scripts/smoke fast mode (~30s): full check once
5# scripts/smoke soak sustained (5min): catches periodic flaps
6#
7# Checks the EXACT request set the frontends make (see dashboard.js,
8# index.html), not a sample. Bodies are inspected, not just status codes
9# (Pages serves the SPA as a fake 200 for unknown paths — never trust a
10# status code you haven't read the body of). Exit 0 = healthy.
11
12set -u
13BASE="https://leaflet-search-backend.fly.dev"
14BUDGET=3 # seconds — anything slower than this is degraded, full stop
15FAILS=0
16
17probe() {
18 ep="$1"; want="$2"
19 body=$(curl -s --max-time "$BUDGET" -w '\n%{http_code} %{time_total}' "$BASE/$ep" 2>/dev/null)
20 meta=$(printf '%s' "$body" | tail -1)
21 code=${meta%% *}; t=${meta##* }
22 payload=$(printf '%s' "$body" | head -c 100)
23 if [ "$code" != "200" ]; then
24 echo "FAIL /$ep -> ${code:-timeout} (${t:->$BUDGET}s)"; FAILS=$((FAILS+1)); return
25 fi
26 case "$payload" in
27 *"$want"*) echo "ok /$ep ${t}s" ;;
28 *) echo "FAIL /$ep 200 but body wrong: $(printf '%s' "$payload" | head -c 60)"; FAILS=$((FAILS+1)) ;;
29 esac
30}
31
32round() {
33 # search modes — the product
34 probe "search?q=test&mode=keyword" '"uri"'
35 probe "search?q=test&mode=semantic" '"uri"'
36 probe "search?q=test&mode=hybrid" '"uri"'
37 # stats page request set (dashboard.js)
38 probe "api/dashboard" '"startedAt"'
39 probe "api/timeline?range=30d" '"points"'
40 probe "api/latency?range=24h" '"endpoints"'
41 probe "activity" '0'
42 probe "stats" '"documents"'
43 probe "tags?format=v2" '"tag"'
44 probe "popular?format=v2" '"'
45 # parallel burst — pages fetch concurrently
46 for ep in "api/dashboard" "api/timeline?range=30d" "stats" "search?q=atproto&mode=keyword"; do
47 ( c=$(curl -s -o /dev/null --max-time "$BUDGET" -w '%{http_code}' "$BASE/$ep" 2>/dev/null)
48 [ "$c" != "200" ] && echo "FAIL parallel /$ep -> ${c:-timeout}" ) &
49 done
50 wait
51}
52
53if [ "${1:-}" = "soak" ]; then
54 i=0
55 while [ $i -lt 10 ]; do
56 i=$((i+1)); echo "--- round $i ---"; round; sleep 25
57 done
58else
59 round
60fi
61
62if [ "$FAILS" = "0" ]; then echo "SMOKE PASS"; else echo "SMOKE FAIL: $FAILS"; exit 1; fi