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

Use "non-blocking" thread for server-less tests in WebTestClient #23936

Closed
bsideup opened this issue Nov 5, 2019 · 0 comments
Closed

Use "non-blocking" thread for server-less tests in WebTestClient #23936

bsideup opened this issue Nov 5, 2019 · 0 comments
Assignees
Milestone

Comments

@bsideup
Copy link

@bsideup bsideup commented Nov 5, 2019

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())
        );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.