Skip to content

Commit 4db2304

Browse files
committed
fix(tests): replace sleep with anyio.Event in test_session
Replace `await anyio.sleep(0.1)` in `run_server` with an `anyio.Event` that the mock client sets after receiving the error response. The server now waits on a precise signal instead of guessing how long the client needs.
1 parent 2fe56e5 commit 4db2304

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/server/test_session.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ async def test_other_requests_blocked_before_initialization():
449449

450450
error_response_received = False
451451
error_code = None
452+
client_done = anyio.Event()
452453

453454
async def run_server():
454455
async with ServerSession(
@@ -460,9 +461,8 @@ async def run_server():
460461
capabilities=ServerCapabilities(),
461462
),
462463
):
463-
# Server should handle the request and send an error response
464-
# No need to process incoming_messages since the error is handled automatically
465-
await anyio.sleep(0.1) # Give time for the request to be processed
464+
# Wait until the client has received and verified the error response
465+
await client_done.wait()
466466

467467
async def mock_client():
468468
nonlocal error_response_received, error_code
@@ -478,6 +478,8 @@ async def mock_client():
478478
error_response_received = True
479479
error_code = error_message.message.error.code
480480

481+
client_done.set()
482+
481483
async with (
482484
client_to_server_send,
483485
client_to_server_receive,

0 commit comments

Comments
 (0)