Update status bar and boot up more quickly with actual radio status

This commit is contained in:
Jack Kingsman
2026-03-07 23:40:18 -08:00
parent f9eb6ebd98
commit 99eddfc2ef
13 changed files with 197 additions and 26 deletions

View File

@@ -43,13 +43,19 @@ class TestHealthFanoutStatus:
@pytest.mark.asyncio
async def test_health_status_ok_when_connected(self, test_db):
"""Health status is 'ok' when radio is connected."""
with patch(
"app.routers.health.RawPacketRepository.get_oldest_undecrypted", return_value=None
with (
patch(
"app.routers.health.RawPacketRepository.get_oldest_undecrypted", return_value=None
),
patch("app.routers.health.radio_manager") as mock_rm,
):
mock_rm.is_setup_in_progress = False
mock_rm.is_setup_complete = True
data = await build_health_data(True, "Serial: /dev/ttyUSB0")
assert data["status"] == "ok"
assert data["radio_connected"] is True
assert data["radio_initializing"] is False
assert data["connection_info"] == "Serial: /dev/ttyUSB0"
@pytest.mark.asyncio
@@ -62,4 +68,22 @@ class TestHealthFanoutStatus:
assert data["status"] == "degraded"
assert data["radio_connected"] is False
assert data["radio_initializing"] is False
assert data["connection_info"] is None
@pytest.mark.asyncio
async def test_health_status_degraded_while_radio_initializing(self, test_db):
"""Health stays degraded while transport is up but post-connect setup is incomplete."""
with (
patch(
"app.routers.health.RawPacketRepository.get_oldest_undecrypted", return_value=None
),
patch("app.routers.health.radio_manager") as mock_rm,
):
mock_rm.is_setup_in_progress = True
mock_rm.is_setup_complete = False
data = await build_health_data(True, "Serial: /dev/ttyUSB0")
assert data["status"] == "degraded"
assert data["radio_connected"] is True
assert data["radio_initializing"] is True

View File

@@ -0,0 +1,48 @@
"""Tests for app startup/lifespan behavior."""
import asyncio
from unittest.mock import AsyncMock, patch
import pytest
from app.main import app, lifespan
class TestStartupLifespan:
@pytest.mark.asyncio
async def test_lifespan_does_not_wait_for_radio_setup(self):
"""HTTP serving should start before post-connect setup finishes."""
setup_started = asyncio.Event()
release_setup = asyncio.Event()
async def slow_setup():
setup_started.set()
await release_setup.wait()
with (
patch("app.main.db.connect", new=AsyncMock()),
patch("app.main.db.disconnect", new=AsyncMock()),
patch("app.radio_sync.ensure_default_channels", new=AsyncMock()),
patch("app.radio.radio_manager.start_connection_monitor", new=AsyncMock()),
patch("app.radio.radio_manager.stop_connection_monitor", new=AsyncMock()),
patch("app.radio.radio_manager.disconnect", new=AsyncMock()),
patch("app.radio.radio_manager.reconnect", new=AsyncMock(return_value=True)),
patch(
"app.radio.radio_manager.post_connect_setup", new=AsyncMock(side_effect=slow_setup)
),
patch("app.fanout.manager.fanout_manager.load_from_db", new=AsyncMock()),
patch("app.fanout.manager.fanout_manager.stop_all", new=AsyncMock()),
patch("app.radio_sync.stop_message_polling", new=AsyncMock()),
patch("app.radio_sync.stop_periodic_advert", new=AsyncMock()),
patch("app.radio_sync.stop_periodic_sync", new=AsyncMock()),
patch("app.websocket.broadcast_health"),
):
cm = lifespan(app)
await asyncio.wait_for(cm.__aenter__(), timeout=0.2)
await asyncio.wait_for(setup_started.wait(), timeout=0.2)
startup_task = app.state.startup_radio_task
assert startup_task.done() is False
release_setup.set()
await asyncio.wait_for(cm.__aexit__(None, None, None), timeout=0.5)