Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

Using StepVerifier.withVirtualTime for a WebClient request using exponential backoff/fixedDelay does not work

$
0
0

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?


Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>