You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/06/12 22:13:24 UTC

[GitHub] mdeuser closed pull request #3694: Add retries to CLI test framework for network errors

mdeuser closed pull request #3694: Add retries to CLI test framework for network errors
URL: https://github.com/apache/incubator-openwhisk/pull/3694
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/common/scala/src/main/scala/whisk/utils/Retry.scala b/common/scala/src/main/scala/whisk/utils/Retry.scala
index e5f7c2219b..e4f4d763af 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 4c379e9d50..d310ff46d4 100644
--- a/tests/src/test/scala/common/TestUtils.java
+++ b/tests/src/test/scala/common/TestUtils.java
@@ -54,11 +54,12 @@
 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 f7f03f6bbb..27ac636814 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) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services