Skip to content

Commit b9ff4d4

Browse files
committed
Add failing test: Fix AdaptiveRetry stopping on Left when shouldPayFailureCost is false
1 parent 953a042 commit b9ff4d4

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

0 commit comments

Comments
 (0)