diff options
Diffstat (limited to 'scripts/test-health-checks.sh')
| -rwxr-xr-x | scripts/test-health-checks.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/test-health-checks.sh b/scripts/test-health-checks.sh index fbe9e47..fa59d8b 100755 --- a/scripts/test-health-checks.sh +++ b/scripts/test-health-checks.sh @@ -121,6 +121,46 @@ else bad "subshell semantics" "array unexpectedly survived a subshell" fi +printf '=== check_app_health ===\n' + +# Unreachable app: must fail, not be mistaken for healthy. +APP_HEALTH_URL="http://127.0.0.1:9/health" +out=$(check_app_health); rc=$? +if [ $rc -ne 0 ] && printf '%s' "$out" | grep -q "app health"; then + ok "catches an unreachable app health endpoint" +else + bad "unreachable health endpoint" "rc=$rc out=$(printf '%s' "$out" | tr '\n' ' ')" +fi + +# A 503 is what /health returns when the database is unreachable — the app is +# listening and answering, so only this check can see it. +python3 - "$tmp/hport" <<'PY2' & +import http.server, socketserver, sys +class H(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(503); self.end_headers() + self.wfile.write(b"db unreachable") + def log_message(self, *a): pass +with socketserver.TCPServer(("127.0.0.1", 0), H) as s: + open(sys.argv[1], "w").write(str(s.server_address[1])) + s.serve_forever() +PY2 +hpid=$! +for _ in $(seq 1 50); do [ -s "$tmp/hport" ] && break; sleep 0.1; done +hport=$(cat "$tmp/hport" 2>/dev/null || echo "") +if [ -n "$hport" ]; then + APP_HEALTH_URL="http://127.0.0.1:${hport}/health" + out=$(check_app_health); rc=$? + if [ $rc -ne 0 ] && printf '%s' "$out" | grep -q "503"; then + ok "catches a listening app whose database ping fails (503)" + else + bad "503 db-ping detection" "rc=$rc out=$(printf '%s' "$out" | tr '\n' ' ')" + fi +else + bad "503 db-ping detection" "could not start stub server" +fi +kill "$hpid" 2>/dev/null; wait "$hpid" 2>/dev/null + printf '=== check_build_stamp ===\n' out=$(check_build_stamp "definitely-not-the-running-commit"); rc=$? |
