diff --git a/test/unit_test/headless/test_agent_presence_server.py b/test/unit_test/headless/test_agent_presence_server.py index 8f90b376..c26b4a7c 100644 --- a/test/unit_test/headless/test_agent_presence_server.py +++ b/test/unit_test/headless/test_agent_presence_server.py @@ -196,7 +196,13 @@ def start(self): client = connected(pipe) try: assert client.closed.wait(1) - assert 'source-close' in events and server.status()['failed'] + # The server drops the connection first and retires its source after it: + # on a slow runner the client sees the close before the retirement lands. + deadline = time.monotonic() + 5 + while time.monotonic() < deadline and not ('source-close' in events and server.status()['failed']): + threading.Event().wait(0.01) + assert 'source-close' in events + assert server.status()['failed'] finally: client.close() with pytest.raises(AgentTaskError):