From 33fba4f647c008c8858a626430078b044237ae76 Mon Sep 17 00:00:00 2001 From: Alex Martel <13215031+manofthepeace@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:16:07 -0500 Subject: [PATCH] fix: exponentialBackoffExpireAt should start at 0 --- .../mutiny/helpers/ExponentialBackoff.java | 2 +- .../mutiny/groups/UniOnFailureRetryTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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();