Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test_server_comms_mark_active_handlers #8927

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions distributed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,12 @@ async def test_server_comms_mark_active_handlers():
ensure this is properly reflected and released. The sentinel for
"open comm but no active handler" is `None`
"""
in_handler = asyncio.Event()
unblock_handler = asyncio.Event()

async def long_handler(comm):
await asyncio.sleep(0.2)
in_handler.set()
await unblock_handler.wait()
return "done"

async with Server({"wait": long_handler}) as server:
Expand All @@ -1063,9 +1066,9 @@ async def long_handler(comm):

comm = await connect(server.address)
await comm.write({"op": "wait"})
while not server._comms:
await asyncio.sleep(0.05)
await in_handler.wait()
assert set(server._comms.values()) == {"wait"}
unblock_handler.set()

assert server.incoming_comms_open == 1
assert server.incoming_comms_active == 1
Expand Down Expand Up @@ -1106,9 +1109,12 @@ def validate_dict(server):

async with Server({}) as server2:
rpc_ = server2.rpc(server.address)
in_handler.clear()
unblock_handler.clear()
task = asyncio.create_task(rpc_.wait())
while not server.incoming_comms_active:
await asyncio.sleep(0.1)

await in_handler.wait()

assert server.incoming_comms_active == 1
assert server.incoming_comms_open == 1
assert server.outgoing_comms_active == 0
Expand All @@ -1120,6 +1126,7 @@ def validate_dict(server):
assert server2.outgoing_comms_open == 1
validate_dict(server)

unblock_handler.set()
await task
assert server.incoming_comms_active == 0
assert server.incoming_comms_open == 1
Expand Down
Loading