Skip to content

Commit b6b1850

Browse files
Brutus5000claude
andauthored
fix(tests): make integration tests pass on macOS (#1091)
* fix(tests): make integration tests pass on macOS On macOS with KqueueSelector, `asyncio.open_connection` returns before the server-side accept callback registers the connection in `ctx.connections`. Three tests in test_servercontext.py raced this scheduling difference and failed deterministically on macOS while passing on Linux CI. - test_unexpected_exception: yield via exhaust_callbacks so the server task emits the "Exception in protocol" log before caplog is checked. - test_drain_connections / test_connection_broken_external: poll ctx.connections until populated before depending on it. exhaust_callbacks cannot be used inside @fast_forward — the outer ticker keeps rescheduling itself and the inner exhaust never exits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(tests): wait for queue boundary in test_info_message `matchmaker_info` is broadcast by the periodic `report_dirties` ticker. On macOS the first broadcast after `game_matchmaking` could be the startup one (queue dirty but no searcher → empty boundary), making the [[300, 700]] assertion fail. Wait for a matchmaker_info where the tmm2v2 queue actually carries a non-empty boundary before asserting. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(tests): bound the connection-registration wait Address CodeRabbit feedback: replace `while not ctx.connections` spin loops with a helper that polls up to a fixed iteration count and raises AssertionError on exhaustion, so tests fail fast instead of hanging if the server never registers the connection. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3c500c0 commit b6b1850

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

tests/integration_tests/test_servercontext.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
from tests.utils import exhaust_callbacks, fast_forward
1313

1414

15+
async def wait_for_connection_registered(ctx, max_iters=1000):
16+
for _ in range(max_iters):
17+
if ctx.connections:
18+
return
19+
await asyncio.sleep(0)
20+
raise AssertionError(
21+
"Server did not register the connection within the allotted iterations"
22+
)
23+
24+
1525
class MockConnection:
1626
def __init__(self):
1727
self.protocol = None
@@ -91,6 +101,7 @@ async def test_connection_broken_external(context):
91101
"""
92102
srv, ctx = context
93103
_, writer = await asyncio.open_connection(*srv.sockets[0].getsockname())
104+
await wait_for_connection_registered(ctx)
94105
writer.close()
95106
# Need this sleep for test to work, otherwise closed protocol isn't detected
96107
await asyncio.sleep(0)
@@ -119,6 +130,7 @@ async def test_unexpected_exception(context, caplog, mocker):
119130

120131
with caplog.at_level("TRACE"):
121132
_, writer = await asyncio.open_connection(*srv.sockets[0].getsockname())
133+
await exhaust_callbacks()
122134

123135
with closing(writer):
124136
assert "Exception in protocol" in caplog.text
@@ -144,6 +156,7 @@ async def test_unexpected_exception_in_connection_lost(context, caplog):
144156
async def test_drain_connections(context):
145157
srv, ctx = context
146158
_, writer = await asyncio.open_connection(*srv.sockets[0].getsockname())
159+
await wait_for_connection_registered(ctx)
147160

148161
with pytest.raises(asyncio.TimeoutError):
149162
await asyncio.wait_for(

tests/integration_tests/test_teammatchmaker.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ async def test_info_message(lobby_server):
7979
"mod": "tmm2v2"
8080
})
8181

82-
msg = await read_until_command(proto, "matchmaker_info")
82+
def tmm2v2_populated(msg):
83+
if msg["command"] != "matchmaker_info":
84+
return False
85+
return any(
86+
q["queue_name"] == "tmm2v2" and q["boundary_80s"]
87+
for q in msg.get("queues", [])
88+
)
89+
90+
msg = await read_until(proto, tmm2v2_populated)
8391

8492
assert msg["queues"]
8593
for queue in msg["queues"]:

0 commit comments

Comments
 (0)