@@ -55,7 +55,7 @@ async def test_continues_after_set_failure(fake_redis):
5555 pass
5656
5757
58- async def test_pump_reconnects_when_heartbeat_goes_stale (monkeypatch ):
58+ async def test_pump_reconnects_when_heartbeat_goes_stale (caplog ):
5959 """When the heartbeat key disappears, the pump must return so the outer
6060 while-True loop can re-subscribe. This is the actual failure mode we hit
6161 when the car power-cycles and the base's pubsub sits connected-but-broken.
@@ -99,10 +99,16 @@ async def handler(msg):
9999 # First iteration: get_message (~1s timeout) returns None, then redis.get
100100 # returns fresh_payload -> last_hb_mono becomes nonzero. Second iteration:
101101 # get_message returns None, redis.get returns None, last_hb_mono > 0 and
102- # > 0.5s old -> pump returns. Sleep 1.8s to be safe past the 1.0s get_message
103- # timeout on iteration 1 plus 0.5s stale on iteration 2.
104- await asyncio .sleep (1.8 )
105- assert task .done (), "pump should have returned after stale heartbeat"
106- assert received == [], "no messages arrived — only reconnect was triggered"
107- # Sanity: we exercised the missing-heartbeat path at least once.
108- assert call_count [0 ] >= 2 , "redis.get should have been polled past the first hit"
102+ # > 0.5s old -> pump returns. Sleep 2.5s to be safe past the 1.0s get_message
103+ # timeout on iteration 1 plus 0.5s stale on iteration 2, with headroom for
104+ # slow CI runners.
105+ with caplog .at_level ("WARNING" ):
106+ await asyncio .sleep (2.5 )
107+ assert task .done (), "pump should have returned after stale heartbeat"
108+ assert received == [], "no messages arrived — only reconnect was triggered"
109+ # Sanity: we exercised the missing-heartbeat path at least once.
110+ assert call_count [0 ] >= 2 , "redis.get should have been polled past the first hit"
111+ assert "heartbeat stale" in caplog .text , (
112+ "expected the reconnect branch to log a warning, "
113+ "but the pump may have ended for a different reason"
114+ )
0 commit comments