Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lite_bootstrap/instruments/healthchecks_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ def render_health_check_data(self, *, health_status: bool = True) -> HealthCheck
return health_check_data

async def define_health_status(self) -> bool:
probes = self.bootstrap_config.health_checks_probes
if not probes:
return await self._define_framework_health_status()
results = await asyncio.gather(
self._define_framework_health_status(),
*(self._run_probe(name, probe) for name, probe in self.bootstrap_config.health_checks_probes.items()),
*(self._run_probe(name, probe) for name, probe in probes.items()),
)
return all(results)

Expand Down
12 changes: 12 additions & 0 deletions tests/instruments/test_healthchecks_instrument.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import asyncio
import time
from unittest.mock import MagicMock

import pytest

from lite_bootstrap.instruments import healthchecks_instrument
from lite_bootstrap.instruments.healthchecks_instrument import HealthChecksConfig, HealthChecksInstrument


Expand Down Expand Up @@ -72,3 +76,11 @@ async def test_healthchecks_status_is_healthy_without_probes() -> None:
def test_healthchecks_render_data_unhealthy() -> None:
instrument = HealthChecksInstrument(bootstrap_config=HealthChecksConfig())
assert instrument.render_health_check_data(health_status=False)["health_status"] is False


async def test_healthchecks_status_without_probes_skips_gather(monkeypatch: pytest.MonkeyPatch) -> None:
gather = MagicMock(side_effect=asyncio.gather)
monkeypatch.setattr(healthchecks_instrument.asyncio, "gather", gather)
instrument = HealthChecksInstrument(bootstrap_config=HealthChecksConfig())
assert await instrument.define_health_status()
gather.assert_not_called()
Loading