refactor(observability): restructure into service-owned packages
This commit is contained in:
@@ -5,6 +5,7 @@ import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from core.api.main import create_app
|
||||
from core.api.observability.stats import WorkerStatsUnavailable
|
||||
from core.api.publisher import (
|
||||
IngestionQueueFull,
|
||||
KafkaPublishError,
|
||||
@@ -327,3 +328,31 @@ def test_successful_request_increments_api_metric(
|
||||
)
|
||||
|
||||
|
||||
def test_stats_endpoint_when_worker_unavailable(
|
||||
publisher: FakePublisher,
|
||||
) -> None:
|
||||
class FailingWorkerStatsClient:
|
||||
async def get_stats(self) -> dict[str, Any]:
|
||||
raise WorkerStatsUnavailable(
|
||||
"Worker stats endpoint unreachable"
|
||||
)
|
||||
|
||||
async def close(self) -> None:
|
||||
pass
|
||||
|
||||
app = create_app(
|
||||
publisher=publisher,
|
||||
worker_stats_client=FailingWorkerStatsClient(),
|
||||
)
|
||||
|
||||
with TestClient(app) as test_client:
|
||||
response = test_client.get("/stats")
|
||||
|
||||
assert response.status_code == 503
|
||||
|
||||
body = response.json()
|
||||
assert body["error"] == "worker_stats_unavailable"
|
||||
assert "Worker stats endpoint unreachable" in body["detail"]
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user