Skip to content

Commit

Permalink
make http_disconnect_while_sending test more robust in the face of sc…
Browse files Browse the repository at this point in the history
…heduling issues
  • Loading branch information
jhominal committed Sep 3, 2022
1 parent dd8045c commit 9161fb8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/middleware/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,18 @@ async def cancel_on_disconnect():

task_group.start_soon(cancel_on_disconnect)

await send(
{
"type": "http.response.body",
"body": b"chunk",
"more_body": True,
}
)
# A timeout is set for 0.1 second in order to ensure that
# cancel_on_disconnect is scheduled by the event loop
with anyio.move_on_after(0.1):
while True:
await send(
{
"type": "http.response.body",
"body": b"chunk ",
"more_body": True,
}
)

pytest.fail(
"http.disconnect should have been received and canceled the scope"
) # pragma: no cover
Expand Down

0 comments on commit 9161fb8

Please sign in to comment.