Files

42 lines
1.1 KiB
Python

import asyncio
from app import health
from app.health import NotConfigured, run_checks
async def test_all_ok():
async def ok():
return "fine"
result = await run_checks({"a": ok, "b": ok})
assert result["ok"] is True
assert result["checks"]["a"] == {"ok": True, "detail": "fine"}
async def test_failure_and_not_configured_flip_overall():
async def ok():
return "fine"
async def boom():
raise RuntimeError("kaputt")
async def missing():
raise NotConfigured
result = await run_checks({"ok": ok, "boom": boom, "missing": missing})
assert result["ok"] is False
assert result["checks"]["boom"] == {"ok": False, "detail": "RuntimeError: kaputt"}
assert result["checks"]["missing"]["detail"] == "nicht konfiguriert"
assert result["checks"]["ok"]["ok"] is True
async def test_timeout(monkeypatch):
monkeypatch.setattr(health, "CHECK_TIMEOUT", 0.05)
async def slow():
await asyncio.sleep(1)
return "never"
result = await run_checks({"slow": slow})
assert result["checks"]["slow"] == {"ok": False, "detail": "Timeout"}