Skip to content

Retry on any errors. #5280

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

Merged
merged 2 commits into from
Jul 15, 2022
Merged
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
8 changes: 4 additions & 4 deletions tests/src/test/scala/common/RunCliCmd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ trait RunCliCmd extends Matchers {
stdinFile: Option[File] = None,
showCmd: Boolean = false,
hideFromOutput: Seq[String] = Seq.empty,
retriesOnNetworkError: Int = 3): RunResult = {
require(retriesOnNetworkError >= 0, "retry count on network error must not be negative")
retriesOnError: Int = 3): RunResult = {
require(retriesOnError >= 0, "retry count on network error must not be negative")

val args = baseCommand
if (verbose) args += "--verbose"
Expand All @@ -79,7 +79,7 @@ trait RunCliCmd extends Matchers {
if (showCmd) println(args.mkString(" "))

val rr =
retry(0, retriesOnNetworkError, () => runCmd(DONTCARE_EXIT, workingDir, sys.env ++ env, stdinFile, args.toSeq))
retry(0, retriesOnError, () => runCmd(DONTCARE_EXIT, workingDir, sys.env ++ env, stdinFile, args.toSeq))

withClue(hideStr(reportFailure(args, expectedExitCode, rr).toString(), hideFromOutput)) {
if (expectedExitCode != TestUtils.DONTCARE_EXIT) {
Expand All @@ -96,7 +96,7 @@ trait RunCliCmd extends Matchers {
/** Retries cmd on network error exit. */
private def retry(i: Int, N: Int, cmd: () => RunResult): RunResult = {
val rr = cmd()
if (rr.exitCode == NETWORK_ERROR_EXIT && i < N) {
if (rr.exitCode != SUCCESS_EXIT && i < N) {
Thread.sleep(1.second.toMillis)
println(s"command will retry to due to network error: $rr")
retry(i + 1, N, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ class RunCliCmdTests extends FlatSpec with RunCliCmd with BeforeAndAfterEach {
it should "not retry commands if retry is disabled" in {
rr = Some(TestRunResult(NETWORK_ERROR_EXIT))
noException shouldBe thrownBy {
cli(Seq.empty, expectedExitCode = ANY_ERROR_EXIT, retriesOnNetworkError = 0)
cli(Seq.empty, expectedExitCode = ANY_ERROR_EXIT, retriesOnError = 0)
}

cmdCount shouldBe 1
}

it should "not retry commands if failure is not retriable" in {
Seq(MISUSE_EXIT, ERROR_EXIT, SUCCESS_EXIT).foreach { code =>
it should "retry commands if any failure is happen" in {
Seq(MISUSE_EXIT, ERROR_EXIT).foreach { code =>
cmdCount = 0

rr = Some(TestRunResult(code))
noException shouldBe thrownBy {
cli(Seq.empty, expectedExitCode = DONTCARE_EXIT, retriesOnNetworkError = 3)
cli(Seq.empty, expectedExitCode = DONTCARE_EXIT, retriesOnError = 3)
}

cmdCount shouldBe 1
cmdCount shouldBe 4
}
}

Expand Down