Skip to content

Commit 665ff8b

Browse files
author
Jianke LIN
committed
test: exercise dispatcher shutdown drain mode
1 parent 4731187 commit 665ff8b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

tests/shared/test_jsonrpc_dispatcher.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,14 @@ async def test_shutdown_error_response_write_is_bounded_when_the_transport_is_we
10981098
):
10991099
"""Cancelling the task group hosting run() completes even when the shutdown error write wedges:
11001100
only `_SHUTDOWN_WRITE_TIMEOUT` releases the join (SDK-defined). A 0-buffer stream nobody reads
1101-
expresses the wedge: run() closes its write stream only after the join, so the send stays parked."""
1101+
expresses the wedge: drain-mode run() closes its write stream only after the join, so the send stays parked."""
11021102
c2s_send, c2s_recv = anyio.create_memory_object_stream[SessionMessage | Exception](1)
11031103
s2c_send, s2c_recv = anyio.create_memory_object_stream[SessionMessage | Exception](0)
1104-
server: JSONRPCDispatcher[TransportContext] = JSONRPCDispatcher(c2s_recv, s2c_send)
1104+
server: JSONRPCDispatcher[TransportContext] = JSONRPCDispatcher(
1105+
c2s_recv,
1106+
s2c_send,
1107+
close_write_stream_on_read_close=False,
1108+
)
11051109
handler_started = anyio.Event()
11061110

11071111
async def park(ctx: DCtx, method: str, params: Mapping[str, Any] | None) -> dict[str, Any]:
@@ -1132,10 +1136,15 @@ async def on_notify(ctx: DCtx, method: str, params: Mapping[str, Any] | None) ->
11321136
@pytest.mark.anyio
11331137
async def test_shutdown_answers_in_flight_request_with_connection_closed():
11341138
"""Read-stream EOF answers a still-running request with CONNECTION_CLOSED (SDK-defined):
1135-
run() keeps the write stream open until the task-group join, so the shielded teardown write lands."""
1139+
drain-mode run() keeps the write stream open until the task-group join, so the shielded teardown write lands."""
11361140
c2s_send, c2s_recv = anyio.create_memory_object_stream[SessionMessage | Exception](4)
11371141
s2c_send, s2c_recv = anyio.create_memory_object_stream[SessionMessage | Exception](4)
1138-
server: JSONRPCDispatcher[TransportContext] = JSONRPCDispatcher(c2s_recv, s2c_send)
1142+
server: JSONRPCDispatcher[TransportContext] = JSONRPCDispatcher(
1143+
c2s_recv,
1144+
s2c_send,
1145+
close_write_stream_on_read_close=False,
1146+
read_eof_drain_timeout_seconds=0.05,
1147+
)
11391148
handler_started = anyio.Event()
11401149

11411150
async def park(ctx: DCtx, method: str, params: Mapping[str, Any] | None) -> dict[str, Any]:

0 commit comments

Comments
 (0)