Skip to content

Commit

Permalink
Merge pull request #1453 from manofthepeace/exponentialBackoff
Browse files Browse the repository at this point in the history
fix: exponentialBackoffExpireAt should start at 0
  • Loading branch information
jponge authored Dec 4, 2023
2 parents 3de0f29 + 33fba4f commit 9064ba0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static Function<Multi<Throwable>, Publisher<Long>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public void testExpireInRetryWithBackOff() {
assertThat(value).isEqualTo("done");
}

@Test
public void testExpireInRetryWithBackOffNotBounded() {
AtomicInteger count = new AtomicInteger();
String value = Uni.createFrom().<String> 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();
Expand Down

0 comments on commit 9064ba0

Please sign in to comment.