File tree Expand file tree Collapse file tree
core/src/test/scala/ox/resilience Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package ox .resilience
2+
3+ import org .scalatest .EitherValues
4+ import org .scalatest .flatspec .AnyFlatSpec
5+ import org .scalatest .matchers .should .Matchers
6+ import ox .scheduling .Schedule
7+
8+ class AdaptiveRetryTest extends AnyFlatSpec with EitherValues with Matchers :
9+
10+ behavior of " AdaptiveRetry"
11+
12+ it should " not pay failureCost if result E is going to be retried and shouldPayFailureCost returns false" in :
13+ // given
14+ var counter = 0
15+ val errorMessage = " boom"
16+
17+ def f : Either [String , Int ] =
18+ counter += 1
19+ Left (errorMessage)
20+
21+ // Bucket smaller than the number of attempts: if the cost were paid, we'd stop early.
22+ val adaptive = AdaptiveRetry (TokenBucket (2 ), 1 , 1 )
23+
24+ // when
25+ val result = adaptive.retryEither(Schedule .immediate.maxRetries(5 ), _ => false )(f)
26+
27+ // then
28+ result.left.value shouldBe errorMessage
29+ // 1 initial + 5 retries, all for free since shouldPayFailureCost returns false
30+ counter shouldBe 6
31+
32+ end AdaptiveRetryTest
You can’t perform that action at this time.
0 commit comments