Skip to content

Commit 7d1c947

Browse files
author
bgagent
committed
fix(agent): fix race condition in test_server backup terminal write test
The test polls /ping until 503 (set when _background_pipeline_failed becomes True) then immediately asserts write_terminal was called. But write_terminal runs after the flag is set in the same except block, creating a race. Fix by joining background threads before asserting.
1 parent 59fa698 commit 7d1c947

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

agent/tests/test_server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def boom(**_kwargs):
6363
assert body["status"] == "unhealthy"
6464
assert body["reason"] == "background_pipeline_failed"
6565

66+
# Wait for the background thread to finish so write_terminal has been called
67+
# (the 503 flag is set before write_terminal in the except block)
68+
with server._threads_lock:
69+
threads = list(server._active_threads)
70+
for t in threads:
71+
t.join(timeout=5)
72+
6673
mock_write.assert_called()
6774
call_kw = mock_write.call_args
6875
assert call_kw[0][0] == "task-crash-1"

0 commit comments

Comments
 (0)