Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout on blocking read for 5000 MILLISECONDS in Spring WEBLUX

Tags:

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.

like image 791
Mikhail Avatar asked Nov 14 '17 13:11

Mikhail


1 Answers

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();
}
like image 180
ROCKY Avatar answered Sep 18 '22 21:09

ROCKY