https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
j

Javier

07/22/2022, 10:54 AM
Has anyone had problems with parallel tests and
MockWebServer
?
y

yschimke

07/23/2022, 10:23 AM
I'm pretty sure, it's more tests being flaky when run in parallel, rather than a direct interaction.
OkHttp's own tests have a OkHttpClientTestRule, and also a MockWebServerRule, which should do the right thing (there is a bug with junit5).
Couterintuitively a big part of the OkHttpClientTestRule is to actually reuse clients, because creating an OkHttpClient with SSLSocketFactory is expensive, and best done less often and pooled in tests.
j

Javier

07/23/2022, 10:57 AM
Should I use that OkHttp rule?
y

yschimke

07/23/2022, 12:03 PM
I don't think we publish it for external use.
To be clear mockwebserver isn't as actively maintained as the rest of OkHttp. I don't want to suggest any extensive changes for you because it may not solve your test flakes problem.
j

Javier

07/23/2022, 2:57 PM
No problem, I can try with Retrofit Mock as they are tests for a Retrofit adapter
👍🏻 1