Merged
Conversation
4dbfbc7 to
339836e
Compare
Kludex
commented
Jan 19, 2024
Comment on lines
+131
to
+145
| async def run_app(tg: anyio.abc.TaskGroup) -> None: | ||
| try: | ||
| await self.app(self.scope, self._asgi_receive, self._asgi_send) | ||
| except anyio.get_cancelled_exc_class(): | ||
| ... | ||
| except BaseException as exc: | ||
| self._send_queue.put(exc) | ||
| raise | ||
| tg.cancel_scope.cancel() | ||
|
|
||
| async with anyio.create_task_group() as tg: | ||
| tg.start_soon(run_app, tg) | ||
| await self.event.wait() | ||
| tg.cancel_scope.cancel() |
Owner
Author
There was a problem hiding this comment.
This is the relevant code.
| try: | ||
| self.close(1000) | ||
| finally: | ||
| self.portal.start_task_soon(self._notify_close) |
tests/test_testclient.py
Outdated
Comment on lines
+257
to
+270
| def test_websocket_not_block_on_close(test_client_factory: Callable[..., TestClient]): | ||
| def app(scope: Scope): | ||
| async def asgi(receive: Receive, send: Send): | ||
| websocket = WebSocket(scope, receive=receive, send=send) | ||
| await websocket.accept() | ||
| while True: | ||
| await anyio.sleep(0.1) | ||
|
|
||
| return asgi | ||
|
|
||
| client = test_client_factory(app) | ||
| with client.websocket_connect("/") as websocket: | ||
| ... | ||
| assert websocket.event.is_set() |
Owner
Author
There was a problem hiding this comment.
This is the relevant test.
Kludex
commented
Jan 19, 2024
| @@ -1,16 +1,20 @@ | |||
| from __future__ import annotations | |||
Owner
Author
There was a problem hiding this comment.
If reviewer complains about this, I can undo the changes.
Owner
Author
|
@encode/maintainers someone? 🙏 |
frankie567
approved these changes
Jan 20, 2024
Contributor
frankie567
left a comment
There was a problem hiding this comment.
LGTM! This approach with the event flag makes total sense.
starlette/testclient.py
Outdated
| except BaseException as exc: | ||
| self._send_queue.put(exc) | ||
| raise | ||
| tg.cancel_scope.cancel() |
Contributor
There was a problem hiding this comment.
Shouldn't we also cancel the task group before raising the exception just above?
e7ae532 to
8f78e7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.