I have the following method I am trying to test (simplified version, but problem is reproducible):
protected Mono<String> executeRequest(String url) {
return webClient.method(HttpMethod.GET)
.uri(url)
.retrieve()
.bodyToMono(String.class)
.doOnError(t -> log.info("Damn, error: {}", t.getMessage()))
.retryWhen(Retry.backoff(5, Duration.ofSeconds(5)));
}
This is the test method:
@Test
void test() {
String mockWebServerUrl = mockWebServer.url("/path")
.uri()
.toString();
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
mockWebServer.enqueue(MockWebServerUtil.createMockResponse(HttpStatus.NOT_FOUND));
StepVerifier.withVirtualTime(() -> dumbClass.executeRequest(mockWebServerUrl))
.expectSubscription()
.thenAwait(Duration.ofDays(100))
.expectError()
.verify();
}
(the thenAwait(Duration.ofDays(100)
is simply to ensure that the retries will for sure finish within the virtual time advance)
I did some debugging and got to the conclusion that if instead of Retry.backoff(5, Duration.ofSeconds(5))
I use Retry.max(5)
the test passes. However, if I use either Retry.backoff
or Retry.fixedDelay
only the first two retries get triggered.
I also saw the accepted answer here but it seems way too complicated for such a simple thing.
Any ideas?
Aleksandar Obreshkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.