Serialize radio disconnect in a lock

This commit is contained in:
Jack Kingsman
2026-03-16 19:25:00 -07:00
parent f8f0b3a8cf
commit c469633a30
2 changed files with 74 additions and 18 deletions
+40
View File
@@ -566,6 +566,46 @@ class TestManualDisconnectCleanup:
assert rm.path_hash_mode_supported is False
assert rm.get_cached_channel_slot("AA" * 16) is None
@pytest.mark.asyncio
async def test_disconnect_waits_for_inflight_radio_operation_cleanup(self):
"""Manual disconnect should wait for the shared radio-operation lock."""
from app.radio import RadioManager
rm = RadioManager()
mc = MagicMock()
mc.disconnect = AsyncMock()
rm._meshcore = mc
holder_entered = asyncio.Event()
allow_release = asyncio.Event()
disconnect_started = asyncio.Event()
async def holder():
async with rm.radio_operation("holder"):
holder_entered.set()
await allow_release.wait()
async def trigger_disconnect():
disconnect_started.set()
await rm.disconnect()
holder_task = asyncio.create_task(holder())
await holder_entered.wait()
disconnect_task = asyncio.create_task(trigger_disconnect())
await disconnect_started.wait()
await asyncio.sleep(0.02)
mc.disconnect.assert_not_awaited()
assert rm.meshcore is mc
allow_release.set()
await holder_task
await disconnect_task
mc.disconnect.assert_awaited_once()
assert rm.meshcore is None
@pytest.mark.asyncio
async def test_pause_connection_marks_connection_undesired(self):
"""Pausing should flip connection_desired off and tear down transport."""