No good way to detect when a websocket is disconnected by the server in tests #2969
Unanswered
jamesh1999
asked this question in
Potential Issue
Replies: 1 comment
-
I should add that this is what I am doing currently. It works for now but has some serious limitations:
It makes it possible to use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following use-case: I'm writing auth tests for a WebSocket service. When the client has insufficient permissions for what it's trying, the connection should be closed by the server with the correct status code. If the service keeps the connection open, I have no guarantee of regular traffic.
Of course, I can do the following:
However, this will block indefinitely if the server did not close the connection - not acceptable for a test suite that could run in CI without a person monitoring.
I use
anyio
in my codebase so I have triedmove_on_after
andfail_after
. Unfortunately none of these can interrupt the receive method and return execution if the server did not close the connection.#2195 #2329 #1140 would have made this possible by adding timeouts. Note: most of the justifications given for not implementing these features do not apply in my use case. There is nothing 'flakey' about the tests. It is simply impossible to check whether the connection has been closed without potentially blocking indefinitely.
#2897 would also be viable as it would enable
anyio
cancellation of the receive call.Open to suggestions for alternative solutions but I think this is a pretty big limitation in the
TestClient
that necessitates looking at ASGI messages directlyBeta Was this translation helpful? Give feedback.
All reactions