diff --git a/implementation/src/main/java/io/smallrye/mutiny/helpers/ExponentialBackoff.java b/implementation/src/main/java/io/smallrye/mutiny/helpers/ExponentialBackoff.java index a735382b9..4d3e28cc0 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/helpers/ExponentialBackoff.java +++ b/implementation/src/main/java/io/smallrye/mutiny/helpers/ExponentialBackoff.java @@ -104,7 +104,7 @@ public static Function, Publisher> randomExponentialBacko AtomicInteger index = new AtomicInteger(); return t -> t .onItem().transformToUni(failure -> { - int iteration = index.incrementAndGet(); + int iteration = index.getAndIncrement(); Duration delay = getNextDelay(firstBackoff, maxBackoff, jitterFactor, iteration); long checkTime = System.currentTimeMillis() + delay.toMillis(); diff --git a/implementation/src/test/java/io/smallrye/mutiny/groups/UniOnFailureRetryTest.java b/implementation/src/test/java/io/smallrye/mutiny/groups/UniOnFailureRetryTest.java index f5fa538df..828488cba 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/groups/UniOnFailureRetryTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/groups/UniOnFailureRetryTest.java @@ -160,6 +160,24 @@ public void testExpireInRetryWithBackOff() { assertThat(value).isEqualTo("done"); } + @Test + public void testExpireInRetryWithBackOffNotBounded() { + AtomicInteger count = new AtomicInteger(); + String value = Uni.createFrom(). emitter(e -> { + int attempt = count.getAndIncrement(); + if (attempt == 0) { + e.fail(new Exception("boom")); + } else { + e.complete("done"); + } + }) + .onFailure().retry().withBackOff(Duration.ofMillis(100)).withJitter(0) + .expireIn(150L) + .await().atMost(Duration.ofSeconds(5)); + + assertThat(value).isEqualTo("done"); + } + @Test public void testExpireAtRetryWithBackOff() { AtomicInteger count = new AtomicInteger();