1

I have a test that can sometimes fail due to a race condition. I was wondering how do I put a retry on the function chain

    final var whoAmIBody =
        WebTestClient.bindToServer()
            .baseUrl(gatewayUrl)
            .build()
            .get()
            .uri("/whoami")
            .header(HttpHeaders.ACCEPT, "application/json")
            .header(HttpHeaders.CONTENT_TYPE, "application/json")
            .header(HttpHeaders.AUTHORIZATION, "Bearer " + responseBody.getAccessToken())
            .exchange()
            .expectStatus()
            .isEqualTo(HttpStatus.OK)
            .expectBody(String.class)
            .returnResult()
            .getResponseBody();
    assertThat(whoAmIBody).isNotNull();

I think I can probably wrap it in a retry loop but I was wondering if there's a way of doing it on the WebTestClient itself.

This Q is for WebTestClient not WebClient: Conditional repeat or retry on Mono with webclient from Spring WebFlux

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

0 Answers0