-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Checklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
The requests.request
interface exposes an stream=True
option which results on the call not waiting for the entire body to arrive.
stream=True
is not handled properly by starlette.testclient._ASGIAdapter.send
, as it is unconditionally waiting for the entire request to finish:
starlette/starlette/testclient.py
Line 240 in e430706
loop.run_until_complete(self.app(scope, receive, send)) |
To reproduce
- Perform an event wait
asyncio.Event
wait()
after your ASGI application responds with your headers (http.response.start
) and first chunk (http.response.body
), this can be easily done inside the generator passed tostarlette.StreamingResponse
. - Set the event via
asyncio.Event
set()
only after doing the request withstream=True
. - Deadlock.
Expected behavior
With stream=True
, TestClient.request should return right after first http.response.body
(asgiref defines server must sent http.response.start
headers only after the first http.response.body
event is generated).
Streaming-related response methods (like iter_content
) should be implemented via awaiting further http.response.body
until more_body
is missing or False
.
Actual behavior
Deadlock.
Additional context
I suspect #533 could be related to this.