Skip to content
Closed
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
32 changes: 32 additions & 0 deletions core/src/test/scala/ox/resilience/AdaptiveRetryTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ox.resilience

import org.scalatest.EitherValues
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import ox.scheduling.Schedule

class AdaptiveRetryTest extends AnyFlatSpec with EitherValues with Matchers:

behavior of "AdaptiveRetry"

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: Either[String, Int] =
counter += 1
Left(errorMessage)

// Bucket smaller than the number of attempts: if the cost were paid, we'd stop early.
val adaptive = AdaptiveRetry(TokenBucket(2), 1, 1)

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

// then
result.left.value shouldBe errorMessage
// 1 initial + 5 retries, all for free since shouldPayFailureCost returns false
counter shouldBe 6

end AdaptiveRetryTest
Loading