mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-06 16:53:38 +02:00
Do our own tracking for contact-on-radio with more correct return state
This commit is contained in:
@@ -954,8 +954,8 @@ class TestAddRemoveRadio:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_already_on_radio(self, test_db, client):
|
||||
"""Adding a contact already on radio returns ok without calling add_contact."""
|
||||
await _insert_contact(KEY_A, on_radio=True)
|
||||
"""Adding a contact already on radio repairs the DB flag and skips add_contact."""
|
||||
await _insert_contact(KEY_A, on_radio=False)
|
||||
|
||||
mock_mc = MagicMock()
|
||||
mock_mc.get_contact_by_key_prefix = MagicMock(return_value=MagicMock()) # On radio
|
||||
@@ -966,6 +966,10 @@ class TestAddRemoveRadio:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "already" in response.json()["message"].lower()
|
||||
contact = await ContactRepository.get_by_key(KEY_A)
|
||||
assert contact is not None
|
||||
assert contact.on_radio is True
|
||||
mock_mc.commands.add_contact.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_from_radio(self, test_db, client):
|
||||
|
||||
@@ -907,3 +907,35 @@ class TestConcurrentChannelSends:
|
||||
msg_type="CHAN", conversation_key=chan_key.upper(), limit=10
|
||||
)
|
||||
assert len(msgs) == 2
|
||||
|
||||
|
||||
class TestChannelSendLockScope:
|
||||
"""Channel send should release the radio lock before DB persistence work."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_channel_message_row_created_after_radio_lock_released(self, test_db):
|
||||
mc = _make_mc(name="TestNode")
|
||||
chan_key = "de" * 16
|
||||
await ChannelRepository.upsert(key=chan_key, name="#lockscope")
|
||||
|
||||
observed_lock_states: list[bool] = []
|
||||
original_create = MessageRepository.create
|
||||
|
||||
async def _assert_lock_then_create(*args, **kwargs):
|
||||
observed_lock_states.append(bool(radio_manager._operation_lock.locked()))
|
||||
return await original_create(*args, **kwargs)
|
||||
|
||||
with (
|
||||
patch("app.routers.messages.require_connected", return_value=mc),
|
||||
patch.object(radio_manager, "_meshcore", mc),
|
||||
patch("app.routers.messages.broadcast_event"),
|
||||
patch(
|
||||
"app.services.message_send.MessageRepository.create",
|
||||
side_effect=_assert_lock_then_create,
|
||||
),
|
||||
):
|
||||
await send_channel_message(
|
||||
SendChannelMessageRequest(channel_key=chan_key, text="Lock scope test")
|
||||
)
|
||||
|
||||
assert observed_lock_states == [False]
|
||||
|
||||
Reference in New Issue
Block a user