fix: wait for req socket send to make sure we dont stay stuck - if there's no... #23

Merged
9828273 merged 19 commits from feat/cb2ui-robot-connections into dev 2025-11-18 12:24:15 +00:00
2 changed files with 11 additions and 13 deletions
Showing only changes of commit 41993a902b - Show all commits

View File

@@ -73,7 +73,7 @@ async def test_send_commands_behaviour_valid_message():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_send_commands_behaviour_invalid_message(caplog): async def test_send_commands_behaviour_invalid_message():
"""Test behaviour with invalid JSON message triggers error logging""" """Test behaviour with invalid JSON message triggers error logging"""
fake_socket = AsyncMock() fake_socket = AsyncMock()
fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}")) fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}"))
@@ -86,9 +86,7 @@ async def test_send_commands_behaviour_invalid_message(caplog):
behaviour = agent.SendCommandsBehaviour() behaviour = agent.SendCommandsBehaviour()
behaviour.agent = agent behaviour.agent = agent
with caplog.at_level("ERROR"):
await behaviour.run() await behaviour.run()
fake_socket.recv_multipart.assert_awaited() fake_socket.recv_multipart.assert_awaited()
fake_socket.send_json.assert_not_awaited() fake_socket.send_json.assert_not_awaited()
assert "Error processing message" in caplog.text

View File

@@ -176,7 +176,7 @@ async def test_setup_creates_socket_and_negotiate_2(zmq_context):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_setup_creates_socket_and_negotiate_3(zmq_context, caplog): async def test_setup_creates_socket_and_negotiate_3(zmq_context):
""" """
Test the functionality of setup with incorrect negotiation message Test the functionality of setup with incorrect negotiation message
""" """
@@ -340,7 +340,7 @@ async def test_setup_creates_socket_and_negotiate_6(zmq_context):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_setup_creates_socket_and_negotiate_7(zmq_context, caplog): async def test_setup_creates_socket_and_negotiate_7(zmq_context):
""" """
Test the functionality of setup with incorrect id Test the functionality of setup with incorrect id
""" """
@@ -379,7 +379,7 @@ async def test_setup_creates_socket_and_negotiate_7(zmq_context, caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_setup_creates_socket_and_negotiate_timeout(zmq_context, caplog): async def test_setup_creates_socket_and_negotiate_timeout(zmq_context):
""" """
Test the functionality of setup with incorrect negotiation message Test the functionality of setup with incorrect negotiation message
""" """
@@ -416,7 +416,7 @@ async def test_setup_creates_socket_and_negotiate_timeout(zmq_context, caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_listen_behaviour_ping_correct(caplog): async def test_listen_behaviour_ping_correct():
fake_socket = AsyncMock() fake_socket = AsyncMock()
fake_socket.send_json = AsyncMock() fake_socket.send_json = AsyncMock()
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}}) fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
@@ -436,7 +436,7 @@ async def test_listen_behaviour_ping_correct(caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_listen_behaviour_ping_wrong_endpoint(caplog): async def test_listen_behaviour_ping_wrong_endpoint():
""" """
Test if our listen behaviour can work with wrong messages (wrong endpoint) Test if our listen behaviour can work with wrong messages (wrong endpoint)
""" """
@@ -471,7 +471,7 @@ async def test_listen_behaviour_ping_wrong_endpoint(caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_listen_behaviour_timeout(zmq_context, caplog): async def test_listen_behaviour_timeout(zmq_context):
fake_socket = zmq_context.return_value.socket.return_value fake_socket = zmq_context.return_value.socket.return_value
fake_socket.send_json = AsyncMock() fake_socket.send_json = AsyncMock()
# recv_json will never resolve, simulate timeout # recv_json will never resolve, simulate timeout
@@ -491,7 +491,7 @@ async def test_listen_behaviour_timeout(zmq_context, caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_listen_behaviour_ping_no_endpoint(caplog): async def test_listen_behaviour_ping_no_endpoint():
""" """
Test if our listen behaviour can work with wrong messages (wrong endpoint) Test if our listen behaviour can work with wrong messages (wrong endpoint)
""" """
@@ -520,7 +520,7 @@ async def test_listen_behaviour_ping_no_endpoint(caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_setup_unexpected_exception(zmq_context, caplog): async def test_setup_unexpected_exception(zmq_context):
fake_socket = zmq_context.return_value.socket.return_value fake_socket = zmq_context.return_value.socket.return_value
fake_socket.send_json = AsyncMock() fake_socket.send_json = AsyncMock()
# Simulate unexpected exception during recv_json() # Simulate unexpected exception during recv_json()
@@ -541,7 +541,7 @@ async def test_setup_unexpected_exception(zmq_context, caplog):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_setup_unpacking_exception(zmq_context, caplog): async def test_setup_unpacking_exception(zmq_context):
# --- Arrange --- # --- Arrange ---
fake_socket = zmq_context.return_value.socket.return_value fake_socket = zmq_context.return_value.socket.return_value
fake_socket.send_json = AsyncMock() fake_socket.send_json = AsyncMock()