Skip to content

Commit

Permalink
test: refine the test of client disconnection after reading request b…
Browse files Browse the repository at this point in the history
…ody (#2639)

Co-authored-by: Marcelo Trylesinski <[email protected]>
  • Loading branch information
iamgodot and Kludex authored Jul 20, 2024
1 parent d3e5327 commit 5f57ef4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,24 @@ async def receiver() -> Message:

def test_request_is_disconnected(test_client_factory: TestClientFactory) -> None:
"""
If a client disconnect occurs while reading request body
then ClientDisconnect should be raised.
If a client disconnect occurs after reading request body
then request will be set disconnected properly.
"""
disconnected_after_response = None

async def app(scope: Scope, receive: Receive, send: Send) -> None:
nonlocal disconnected_after_response

request = Request(scope, receive)
await request.body()
body = await request.body()
disconnected = await request.is_disconnected()
response = JSONResponse({"disconnected": disconnected})
response = JSONResponse({"body": body.decode(), "disconnected": disconnected})
await response(scope, receive, send)
disconnected_after_response = await request.is_disconnected()

client = test_client_factory(app)
response = client.get("/")
assert response.json() == {"disconnected": False}
response = client.post("/", content="foo")
assert response.json() == {"body": "foo", "disconnected": False}
assert disconnected_after_response


Expand Down

0 comments on commit 5f57ef4

Please sign in to comment.