Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/ox/resilience/AdaptiveRetry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case class AdaptiveRetry(
// If we want to retry we try to acquire tokens from bucket
if config.resultPolicy.isWorthRetrying(value) then
if shouldPayFailureCost(Left(value)) then ScheduleStop(!tokenBucket.tryAcquire(failureCost))
else ScheduleStop.Yes
else ScheduleStop.No
else ScheduleStop.Yes
case Right(value) =>
// If we are successful, we release tokens to bucket and end schedule
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/scala/ox/resilience/ImmediateRetryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,22 @@ class ImmediateRetryTest extends AnyFlatSpec with EitherValues with TryValues wi
result.value shouldBe message
counter shouldBe 6

it should "not pay failureCost if result E is going to be retried and shouldPayFailureCost returns false" in:
// given
var counter = 0
val errorMessage = "boom"

def f =
counter += 1
Left(errorMessage)

val adaptive = AdaptiveRetry(TokenBucket(2), 1, 1)
// when
val result = adaptive.retryEither(Schedule.immediate.maxRetries(5), _ => false)(f)

// then
result.left.value shouldBe errorMessage
// all attempts are made for free, without paying the failure cost: one initial + five retries
counter shouldBe 6

end ImmediateRetryTest
Loading