Main Tutorials

Spring WebFlux Test – Timeout on blocking read for 5000 MILLISECONDS

Test a Spring Webflux endpoint with the WebTestClient, and hits the following error messages. Is this possible to increase the timeout?


java.lang.IllegalStateException: Timeout on blocking read for 5000 MILLISECONDS

	at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:117)
	at reactor.core.publisher.Mono.block(Mono.java:1524)
	at org.springframework.test.web.reactive.server.ExchangeResult.formatBody(ExchangeResult.java:247)
	at org.springframework.test.web.reactive.server.ExchangeResult.toString(ExchangeResult.java:216)
	at java.base/java.lang.String.valueOf(String.java:2788)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:135)
	at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:200)

Solution

By default, the WebTestClient will be timeout after 5 seconds. We can configure the timeout with @AutoConfigureWebTestClient


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient(timeout = "10000")//10 seconds
public class TestCommentWebApplication {

    @Autowired
    private WebTestClient webClient;

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Anil
4 years ago

Unfortunately, it still failed. IT prints the timeout as 5 sec even though changed to 10 sec

java.lang.IllegalStateException: Timeout on blocking read for 5000 MILLISECONDS

@AutoConfigureWebTestClient(timeout = “10000”)

Durga Malleswara Rao Uppala
2 years ago

While build web test client you can give response timeout.

WebTestClient.bindToServer()
        .responseTimeout(Duration.ofMillis(10000L))
        .baseUrl(String.format(“http://localhost:%s”, yourPort))
        .build();