fix: fix test race condition

ref: N25B-301
This commit is contained in:
2025-11-25 11:21:25 +01:00
parent ef00c03ec5
commit e5949a7273
9 changed files with 25 additions and 58 deletions

View File

@@ -25,24 +25,14 @@ async def test_setup_bind(zmq_context, mocker):
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
# Swallow background task coroutines to avoid un-awaited warnings
class Swallow:
def __init__(self):
self.calls = 0
async def __call__(self, coro):
self.calls += 1
coro.close()
swallow = Swallow()
agent.add_behavior = swallow
agent.add_behavior = MagicMock()
await agent.setup()
fake_socket.bind.assert_any_call("tcp://localhost:5555")
fake_socket.connect.assert_any_call("tcp://internal:1234")
fake_socket.setsockopt.assert_any_call(zmq.SUBSCRIBE, b"command")
assert swallow.calls == 1
agent.add_behavior.assert_called_once()
@pytest.mark.asyncio
@@ -53,22 +43,13 @@ async def test_setup_connect(zmq_context, mocker):
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
class Swallow:
def __init__(self):
self.calls = 0
async def __call__(self, coro):
self.calls += 1
coro.close()
swallow = Swallow()
agent.add_behavior = swallow
agent.add_behavior = MagicMock()
await agent.setup()
fake_socket.connect.assert_any_call("tcp://localhost:5555")
fake_socket.connect.assert_any_call("tcp://internal:1234")
assert swallow.calls == 1
agent.add_behavior.assert_called_once()
@pytest.mark.asyncio