-
-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestClient.request does not honor timeout #1108
Comments
Closing as per #1109 timeouts == flaky tests |
Okay - that comment is a bit brief. But see #1109. Frameworks such as Flask and Django have always had this constraint. It's something that we can live with as well. |
I have a case where a "timeout" would be useful in testing how the server handles disconnecting clients. So a "timeout" where the client times out immediately after sending the request would be useful and should not be flaky since no actual timing is involved. |
This may help: 25a52fe |
I was just looking at this again last week. I never could figure out how to get around the Anyways, I sort of came to the conclusion that we should remove our individual test timeouts from our service unit tests as they were a sort of anti-pattern. Many of our service unit tests also serve as integration tests, but we probably need to separate those out better. |
Checklist
master
.Describe the bug
timeout
parameter exposed intestclient.request
has no effect. Looking through the code, it seems as though we use the same interface asrequests
package but only a subset of those features are supported bytestclient
To reproduce
Expected behavior
A TimeoutException should be raised if the timeout specified in request is shorter than the time the request takes.
Actual behavior
No timeout exceptions are raised when setting timeout.
Additional context
In CI/CD context, testing our own endpoints which, during integration testing, may timeout, is very helpful. If this is unsupported, it might be nice to have a list of differences between the interface of requests/testclient (this might include #1102).
I did look a bit how the requests package implemented their timeout exceptions, and to be completely honest I got a bit lost going down the rabbit hole of
requests
->urllib3
->http.client
. Since we're using a different adapter for the testclient, it might be some work to reimplement all the way down the timeout exceptions in the same way.I did notice that the
async_asgi_testclient
works with a timeout. Of course, it requires an async endpoint. But their implementation might still be useful?Found that
httpx
had a similar issue with timeout having no effect when mounting an app with its client.The text was updated successfully, but these errors were encountered: