Skip to content

Commit 4a69be2

Browse files
authored
Retry on any errors. (#5280)
* Retry on any errors. * Change the variable name.
1 parent 53b2352 commit 4a69be2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

tests/src/test/scala/common/RunCliCmd.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ trait RunCliCmd extends Matchers {
6666
stdinFile: Option[File] = None,
6767
showCmd: Boolean = false,
6868
hideFromOutput: Seq[String] = Seq.empty,
69-
retriesOnNetworkError: Int = 3): RunResult = {
70-
require(retriesOnNetworkError >= 0, "retry count on network error must not be negative")
69+
retriesOnError: Int = 3): RunResult = {
70+
require(retriesOnError >= 0, "retry count on network error must not be negative")
7171

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

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

8484
withClue(hideStr(reportFailure(args, expectedExitCode, rr).toString(), hideFromOutput)) {
8585
if (expectedExitCode != TestUtils.DONTCARE_EXIT) {
@@ -96,7 +96,7 @@ trait RunCliCmd extends Matchers {
9696
/** Retries cmd on network error exit. */
9797
private def retry(i: Int, N: Int, cmd: () => RunResult): RunResult = {
9898
val rr = cmd()
99-
if (rr.exitCode == NETWORK_ERROR_EXIT && i < N) {
99+
if (rr.exitCode != SUCCESS_EXIT && i < N) {
100100
Thread.sleep(1.second.toMillis)
101101
println(s"command will retry to due to network error: $rr")
102102
retry(i + 1, N, cmd)

tests/src/test/scala/org/apache/openwhisk/common/RunCliCmdTests.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ class RunCliCmdTests extends FlatSpec with RunCliCmd with BeforeAndAfterEach {
6868
it should "not retry commands if retry is disabled" in {
6969
rr = Some(TestRunResult(NETWORK_ERROR_EXIT))
7070
noException shouldBe thrownBy {
71-
cli(Seq.empty, expectedExitCode = ANY_ERROR_EXIT, retriesOnNetworkError = 0)
71+
cli(Seq.empty, expectedExitCode = ANY_ERROR_EXIT, retriesOnError = 0)
7272
}
7373

7474
cmdCount shouldBe 1
7575
}
7676

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

8181
rr = Some(TestRunResult(code))
8282
noException shouldBe thrownBy {
83-
cli(Seq.empty, expectedExitCode = DONTCARE_EXIT, retriesOnNetworkError = 3)
83+
cli(Seq.empty, expectedExitCode = DONTCARE_EXIT, retriesOnError = 3)
8484
}
8585

86-
cmdCount shouldBe 1
86+
cmdCount shouldBe 4
8787
}
8888
}
8989

0 commit comments

Comments
 (0)