Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test case for retry.When #166

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions retry/src/main/scala/Policy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ object Backoff {
}
}

/** A retry policy in which the a failure determines the way a future should be retried. The partial function provided
* may define the domain of both the success OR exceptional failure of a future fails explicitly.
/** A retry policy in which the type of failure determines the way a future should be retried. The partial function
* provided may define the domain of both the success OR exceptional failure of a future fails explicitly.
*
* {{{
* val policy = retry.When {
Expand Down
28 changes: 28 additions & 0 deletions retry/src/test/scala/PolicySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -607,5 +607,33 @@ abstract class PolicySpec extends AsyncFunSpec with BeforeAndAfterAll {
assert(retried.get() == 1)
}
}

it("should stop repeating when the failure changes") {
implicit val success = Success[Boolean](identity)
object RecoverableException extends RuntimeException("recoverable exception")
object FatalException extends RuntimeException("fatal exception")
val retried = new AtomicInteger()
val retriedUntilFailure = 5
def run() = {
println(retried.get())
if (retried.getAndIncrement() < retriedUntilFailure) {
Future.failed(RecoverableException)
} else {
if(retried.get() > 2 * retriedUntilFailure) {
// this state should never be reached
Future(true)
} else Future.failed(FatalException)
}
}

val policy = When {
case FatalException => throw FatalException
case _ => Directly.forever
}
policy(run()).failed.map { t =>
assert(t.getMessage === "fatal exception")
assert(retried.get() == 5)
}
}
}
}
Loading