This is an automated email from the ASF dual-hosted git repository. mdeuser pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new f4d8ce5 Add retries to CLI test framework for network errors (#3694) f4d8ce5 is described below commit f4d8ce5009381cdf3385a69c383eca2fd01a0282 Author: James Dubee <jwdu...@us.ibm.com> AuthorDate: Tue Jun 12 18:13:22 2018 -0400 Add retries to CLI test framework for network errors (#3694) * Add retries to CLI test framework for network errors * Do not retry when expecting a network failure * Use withClue * Print message when network error occurs * Show retry message * Use foreach instead of pattern matching retry message --- .../scala/src/main/scala/whisk/utils/Retry.scala | 8 ++++-- tests/src/test/scala/common/TestUtils.java | 11 ++++---- tests/src/test/scala/common/Wsk.scala | 29 ++++++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/common/scala/src/main/scala/whisk/utils/Retry.scala b/common/scala/src/main/scala/whisk/utils/Retry.scala index e5f7c22..e4f4d76 100644 --- a/common/scala/src/main/scala/whisk/utils/Retry.scala +++ b/common/scala/src/main/scala/whisk/utils/Retry.scala @@ -31,15 +31,19 @@ object retry { * @return the result of fn iff it is successful * @throws Throwable exception from fn (or an illegal argument exception if N is < 1) */ - def apply[T](fn: => T, N: Int = 3, waitBeforeRetry: Option[Duration] = Some(50.milliseconds)): T = { + def apply[T](fn: => T, + N: Int = 3, + waitBeforeRetry: Option[Duration] = Some(50.milliseconds), + retryMessage: Option[String] = None): T = { require(N >= 1, "maximum number of fn applications must be greater than 1") waitBeforeRetry.foreach(t => Thread.sleep(t.toMillis)) // initial wait if any try fn catch { case _ if N > 1 => + retryMessage.foreach(println) waitBeforeRetry.foreach(t => Thread.sleep(t.toMillis)) - retry(fn, N - 1, waitBeforeRetry) + retry(fn, N - 1, waitBeforeRetry, retryMessage) } } } diff --git a/tests/src/test/scala/common/TestUtils.java b/tests/src/test/scala/common/TestUtils.java index 4c379e9..d310ff4 100644 --- a/tests/src/test/scala/common/TestUtils.java +++ b/tests/src/test/scala/common/TestUtils.java @@ -54,11 +54,12 @@ import junit.runner.Version; public class TestUtils { protected static final Logger logger = Logger.getLogger("basic"); - public static final int SUCCESS_EXIT = 0; - public static final int ERROR_EXIT = 1; - public static final int MISUSE_EXIT = 2; - public static final int DONTCARE_EXIT = -1; // any value is ok - public static final int ANY_ERROR_EXIT = -2; // any non-zero value is ok + public static final int SUCCESS_EXIT = 0; + public static final int ERROR_EXIT = 1; + public static final int MISUSE_EXIT = 2; + public static final int DONTCARE_EXIT = -1; // any value is ok + public static final int ANY_ERROR_EXIT = -2; // any non-zero value is ok + public static final int NETWORK_ERROR_EXIT = 3; public static final int ACCEPTED = 202; // 202 public static final int BAD_REQUEST = 144; // 400 - 256 = 144 diff --git a/tests/src/test/scala/common/Wsk.scala b/tests/src/test/scala/common/Wsk.scala index f7f03f6..27ac636 100644 --- a/tests/src/test/scala/common/Wsk.scala +++ b/tests/src/test/scala/common/Wsk.scala @@ -1036,13 +1036,28 @@ trait RunWskCmd extends BaseRunWsk { val args = baseCommand if (verbose) args += "--verbose" if (showCmd) println(args.mkString(" ") + " " + params.mkString(" ")) - val rr = TestUtils.runCmd( - DONTCARE_EXIT, - workingDir, - TestUtils.logger, - sys.env ++ env, - stdinFile.getOrElse(null), - args ++ params: _*) + val rr = + retry( + { + val rr = TestUtils.runCmd( + DONTCARE_EXIT, + workingDir, + TestUtils.logger, + sys.env ++ env, + stdinFile.getOrElse(null), + args ++ params: _*) + + if (expectedExitCode != NETWORK_ERROR_EXIT) { + withClue(hideStr(reportFailure(args ++ params, expectedExitCode, rr).toString(), hideFromOutput)) { + rr.exitCode should not be NETWORK_ERROR_EXIT + } + } + + rr + }, + 3, + Some(1.second), + Some(s"CLI encountered a network error, retrying command...")) withClue(hideStr(reportFailure(args ++ params, expectedExitCode, rr).toString(), hideFromOutput)) { if (expectedExitCode != TestUtils.DONTCARE_EXIT) { -- To stop receiving notification emails like this one, please contact mdeu...@apache.org.