Skip to content
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

Add default timeout to MockWebServer.takeRequest() #7419

Open
jhyot opened this issue Aug 10, 2022 · 1 comment
Open

Add default timeout to MockWebServer.takeRequest() #7419

jhyot opened this issue Aug 10, 2022 · 1 comment
Labels
enhancement Feature not a bug

Comments

@jhyot
Copy link

jhyot commented Aug 10, 2022

MockWebServer.takeRequest() without parameters will block indefinitely if there is no request coming. In my opinion this is a bit unfortunate, because in case of e.g. a bug in our code which results in no calls being made, the complete test suite stalls. Another use case is when writing test-first code, then there is often no request yet programmed, yet I cannot run the test to assert that it is failing.

The solution is to use the overloaded method with an explicit timeout. But this makes the code less readable, and there are potentially many repetitions of the MockWebServer.takeRequest(xxx, SECONDS) (and similar) calls, which are basically noise.

This is why I want to suggest a feature to be able to set a default timeout, either per MockWebServer instance, or globally. Many test libraries like Awaitility or Mockito use static global variables for some baseline settings.

@jhyot jhyot added the enhancement Feature not a bug label Aug 10, 2022
@yschimke
Copy link
Collaborator

There is a good opportunity with OkHttp 5 to look at this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

No branches or pull requests

2 participants