Skip to content

Commit 349bdf3

Browse files
committed
fix: close write_stream in tests to prevent task group hang
The two new buffer tests did not close write_stream, causing stdout_writer to block indefinitely on write_stream_reader iteration. This prevented the task group from exiting, hanging the test until CI timeout.
1 parent 084ac9e commit 349bdf3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/server/test_stdio.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def test_stdio_server_with_buffer_size():
8282
stdout=anyio.AsyncFile(stdout),
8383
read_stream_buffer_size=5,
8484
write_stream_buffer_size=5,
85-
) as (read_stream, _write_stream):
85+
) as (read_stream, write_stream):
8686
received_messages: list[JSONRPCMessage] = []
8787
async with read_stream:
8888
async for message in read_stream:
@@ -95,6 +95,7 @@ async def test_stdio_server_with_buffer_size():
9595
assert len(received_messages) == 3
9696
for i, msg in enumerate(received_messages, 1):
9797
assert msg == JSONRPCRequest(jsonrpc="2.0", id=i, method="ping")
98+
await write_stream.aclose()
9899

99100

100101
@pytest.mark.anyio
@@ -118,7 +119,7 @@ async def test_stdio_server_buffered_does_not_block_reader():
118119
stdin=anyio.AsyncFile(stdin),
119120
stdout=anyio.AsyncFile(stdout),
120121
read_stream_buffer_size=num_messages,
121-
) as (read_stream, _write_stream):
122+
) as (read_stream, write_stream):
122123
# Give the reader time to buffer all messages
123124
await anyio.sleep(0.1)
124125

@@ -134,3 +135,4 @@ async def test_stdio_server_buffered_does_not_block_reader():
134135
break
135136

136137
assert len(received) == num_messages
138+
await write_stream.aclose()

0 commit comments

Comments
 (0)