'Timeout on blocking read for 5000 MILLISECONDS in Spring Webflux
I wrote a test for Handler (Spring Webflux)
@Test
public void checkServicesHandlerTest() {
Request request = new Request();
request.setMsisdn("ffdfdfd");
this.testClient.post().uri("/check")
.body(Mono.just(request), Request.class)
.exchange().expectStatus().isOk();
}
But in result I have an error.
Timeout on blocking read for 5000 MILLISECONDS
The handler is simple:
public Mono<ServerResponse> check(ServerRequest request) {
Request request = request.bodyToMono(Request.class).block();
Where is the problem? If i send a direct request to server all is ok.
Solution 1:[1]
I was seeing similar issue and Exception when running Integration tests some of them aggregates responses from multiple other services which has database access and stuff. So we were seeing this issue intermittently when running Integration tests. We are using Spring Boot 2.0.0.RC1 and Junit 5 with Gradle. I did this to resolve the issue. The key is mutating the webclient with a response timeout of 30 seconds the worst case.
@Autowired
private WebTestClient webTestClient;
@BeforeEach
public void setUp() {
webTestClient = webTestClient.mutate()
.responseTimeout(Duration.ofMillis(30000))
.build();
}
Solution 2:[2]
You can override the timeout by using the annotation @AutoConfigureWebTestClient(timeout = "36000").
for example :
@AutoConfigureWebTestClient(timeout = "36000")
@SpringBootTest
class MyTestClass {
}
Solution 3:[3]
With the WebTestClient you can use @AutoConfigureWebTestClient(timeout = "36000"),
the timeout value being a value of your choice. Especially, consider the response time of your third-party service.
Solution 4:[4]
In case of Kotlin test it could be following example:
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class RouterTests {
lateinit var client: WebTestClient
private val dealService: DealService = QshDealService()
private val dealStream: StreamHandler<MarketData> = DealStream(dealService)
private lateinit var fileService: FileService
@BeforeAll
fun init() {
val streamHandlers: Map<String, StreamHandler<MarketData>> = mapOf("dealStream" to dealStream)
fileService = CommonFilesService(streamHandlers)
val filesHandler = QshFilesHandler(fileService)
this.client = WebTestClient
.bindToRouterFunction(QshRouter(filesHandler).route())
.configureClient()
.responseTimeout(Duration.ofMillis(30000))
.build()
}
@Test
fun whenRequestToRoute_thenStatusShouldBeOk() {
...
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zb226 |
| Solution 2 | |
| Solution 3 | Trippletech Magabe |
| Solution 4 | Dada |
