Skip to content

Commit

Permalink
Merge pull request #3 from lsst-dm/tickets/DM-31215
Browse files Browse the repository at this point in the history
DM-31215: Add health check endpoint to the server
  • Loading branch information
spenczar authored Aug 13, 2021
2 parents 4385145 + 0b33ca0 commit d1cc45a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions alertdb/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def create_server(backend: AlertDatabaseBackend) -> FastAPI:

app = FastAPI()

@app.get("/v1/health")
def healthcheck():
return Response(content=b"OK")

@app.get("/v1/schemas/{schema_id}")
def get_schema(schema_id: str):
try:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def test_get_missing_schema(self):
response = self._get_schema("bogus")
self.assertEqual(response.status_code, 404)

def test_healthcheck(self):
"""Test that the healthcheck endpoint returns 200."""
response = self.client.get("/v1/health")
self.assertEqual(response.status_code, 200)

def _get_alert(self, alert_id: str) -> requests.Response:
return self.client.get(f"/v1/alerts/{alert_id}")

Expand Down
19 changes: 19 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from fastapi.testclient import TestClient

from alertdb.server import create_server
from alertdb.storage import FileBackend


@pytest.fixture
def file_backend(tmp_path):
"""Pytest fixture for a file-based backend"""
yield FileBackend(str(tmp_path))


def test_server_healthcheck(file_backend):
"""Test that the server responds on the healthcheck endpoint."""
server = create_server(file_backend)
client = TestClient(server)
response = client.get("/v1/health")
assert response.status_code == 200

0 comments on commit d1cc45a

Please sign in to comment.