Add Pico communication timeout tracking
This commit is contained in:
@@ -350,3 +350,79 @@ def test_communication_service_http_fallback_relay():
|
||||
assert state.relays["fridge"] is True
|
||||
assert fake_uart.writes == []
|
||||
assert fake_requests.urls == ["http://192.168.4.1/relay/fridge/on"]
|
||||
|
||||
|
||||
def test_communication_service_marks_uart_connected_on_status():
|
||||
from comms.uart_client import UartClient
|
||||
from comms.communication_service import CommunicationService
|
||||
|
||||
fake = FakeUart()
|
||||
fake.read_chunks = [
|
||||
b'{"type":"status_response","timestamp":1,"network":{"uart_connected":true}}\n'
|
||||
]
|
||||
|
||||
state = AppState()
|
||||
current_time = [100.0]
|
||||
|
||||
service = CommunicationService(
|
||||
UartClient(fake),
|
||||
state,
|
||||
clock=lambda: current_time[0],
|
||||
timeout_seconds=5,
|
||||
)
|
||||
|
||||
service.poll()
|
||||
|
||||
assert state.network["uart_connected"] is True
|
||||
assert service.last_status_received_at == 100.0
|
||||
|
||||
|
||||
def test_communication_service_marks_uart_disconnected_after_timeout():
|
||||
from comms.uart_client import UartClient
|
||||
from comms.communication_service import CommunicationService
|
||||
|
||||
fake = FakeUart()
|
||||
fake.read_chunks = [
|
||||
b'{"type":"status_response","timestamp":1,"network":{"uart_connected":true}}\n'
|
||||
]
|
||||
|
||||
state = AppState()
|
||||
current_time = [100.0]
|
||||
|
||||
service = CommunicationService(
|
||||
UartClient(fake),
|
||||
state,
|
||||
clock=lambda: current_time[0],
|
||||
timeout_seconds=5,
|
||||
)
|
||||
|
||||
service.poll()
|
||||
assert state.network["uart_connected"] is True
|
||||
|
||||
current_time[0] = 106.0
|
||||
service.poll()
|
||||
|
||||
assert state.network["uart_connected"] is False
|
||||
|
||||
|
||||
def test_communication_service_auto_selects_http_fallback_when_uart_down():
|
||||
from comms.uart_client import UartClient
|
||||
from comms.http_client import HttpClient
|
||||
from comms.communication_service import CommunicationService
|
||||
|
||||
fake_uart = FakeUart()
|
||||
fake_requests = FakeRequests()
|
||||
|
||||
state = AppState()
|
||||
service = CommunicationService(
|
||||
UartClient(fake_uart),
|
||||
state,
|
||||
HttpClient(fake_requests),
|
||||
clock=lambda: 100.0,
|
||||
timeout_seconds=5,
|
||||
)
|
||||
|
||||
service.poll()
|
||||
|
||||
assert service.auto_select_transport() is True
|
||||
assert service.use_http_fallback is True
|
||||
|
||||
Reference in New Issue
Block a user