Problem
As was reported on Gitter, WebTestClient
uses the same thread to execute the controller's methods.
In case of Webflux, it means that Reactor's built-in blocking call detection (e.g. calling mono.block()
) or more advanced checks like BlockHound will not detect anything, since the thread is not non-blocking.
Since it creates a false positive feeling that the app does not have blocking calls, it would be better if WebTestClient
with Webflux would mimic the non-blocking nature of the Webflux calls and move the subscription to e.g. Schedulers.parallel()
Workaround
It is possible to customize the WebTestClient
and manually move the subscription to the parallel scheduler:
@Component
public class WebTestClientConfig implements WebTestClientBuilderCustomizer {
@Override
public void customize(WebTestClient.Builder builder) {
builder.filter((clientRequest, next) ->
next.exchange(clientRequest).subscribeOn(Schedulers.parallel())
);
}
}
Comment From: gvsandeep2647
Can someone help me out here : https://stackoverflow.com/questions/64924128/why-is-webtestclient-is-throwing-blocking-error-blockhound ?