You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cb...@apache.org on 2018/02/20 07:11:17 UTC

[incubator-openwhisk] branch master updated: Actually retry package remove on conflict. (#3303)

This is an automated email from the ASF dual-hosted git repository.

cbickel 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 94ed1db  Actually retry package remove on conflict. (#3303)
94ed1db is described below

commit 94ed1db74625b0084216b7b493082b7d28135b3f
Author: Markus Thömmes <ma...@me.com>
AuthorDate: Tue Feb 20 08:11:13 2018 +0100

    Actually retry package remove on conflict. (#3303)
    
    The AssetHelper is supposed to retry a package deletion if it returns a conflic. This can happen, if the package contained other entities (like an action), which got deleted first but the package's view does not yet reflect that deletion. The DELETE call will then complain about "entities still in package". A retry resolves that issue.
    
    - Some cleanup of the helpers file.
    - Refactoring of the annotations helper.
---
 tests/src/test/scala/common/WskTestHelpers.scala | 30 ++++++++++++------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tests/src/test/scala/common/WskTestHelpers.scala b/tests/src/test/scala/common/WskTestHelpers.scala
index c9073f6..dbd03ca 100644
--- a/tests/src/test/scala/common/WskTestHelpers.scala
+++ b/tests/src/test/scala/common/WskTestHelpers.scala
@@ -28,6 +28,7 @@ import scala.concurrent.duration.Duration
 import scala.concurrent.duration.DurationInt
 
 import spray.json._
+import spray.json.DefaultJsonProtocol._
 
 import TestUtils.RunResult
 import TestUtils.CONFLICT
@@ -56,7 +57,7 @@ object ActivationResponse extends DefaultJsonProtocol {
  * @param start an Instant to save the start time of activation
  * @param end an Instant to save the end time of activation
  * @param duration a Long to save the duration of the activation
- * @param cases String to save the cause of failure if the activation fails
+ * @param cause String to save the cause of failure if the activation fails
  * @param annotations a list of JSON objects to save the annotations of the activation
  */
 case class ActivationResult(activationId: String,
@@ -68,15 +69,10 @@ case class ActivationResult(activationId: String,
                             cause: Option[String],
                             annotations: Option[List[JsObject]]) {
 
-  def getAnnotationValue(key: String): Option[JsValue] = {
-    Try {
-      val annotation = annotations.get.filter(x => x.getFields("key")(0) == JsString(key))
-      assert(annotation.size == 1) // only one annotation with this value
-      val value = annotation(0).getFields("value")
-      assert(value.size == 1)
-      value(0)
-    }.toOption
-  }
+  def getAnnotationValue(key: String): Option[JsValue] =
+    annotations
+      .flatMap(_.find(_.fields("key").convertTo[String] == key))
+      .map(_.fields("value"))
 }
 
 object ActivationResult extends DefaultJsonProtocol {
@@ -154,7 +150,7 @@ trait WskTestHelpers extends Matchers {
    * list that is iterated at the end of the test so that these entities are deleted
    * (from most recently created to oldest).
    */
-  def withAssetCleaner(wskprops: WskProps)(test: (WskProps, AssetCleaner) => Any) = {
+  def withAssetCleaner(wskprops: WskProps)(test: (WskProps, AssetCleaner) => Any): Unit = {
     // create new asset list to track what must be deleted after test completes
     val assetsToDeleteAfterTest = new Assets()
 
@@ -168,14 +164,18 @@ trait WskTestHelpers extends Matchers {
     } finally {
       // delete assets in reverse order so that was created last is deleted first
       val deletedAll = assetsToDeleteAfterTest.reverse map {
-        case ((cli, n, delete)) =>
+        case (cli, n, delete) =>
           n -> Try {
             cli match {
               case _: BasePackage if delete =>
-                val rr = cli.delete(n)(wskprops)
+                // sanitize ignores the exit code, so we can inspect the actual result and retry accordingly
+                val rr = cli.sanitize(n)(wskprops)
                 rr.exitCode match {
                   case CONFLICT | StatusCodes.Conflict.intValue =>
-                    whisk.utils.retry(cli.delete(n)(wskprops), 5, Some(1.second))
+                    whisk.utils.retry({
+                      println("package deletion conflict, view computation delay likely, retrying...")
+                      cli.delete(n)(wskprops)
+                    }, 5, Some(1.second))
                   case _ => rr
                 }
               case _ => if (delete) cli.delete(n)(wskprops) else cli.sanitize(n)(wskprops)
@@ -260,7 +260,7 @@ trait WskTestHelpers extends Matchers {
       check(parsed)
     } catch {
       case error: Throwable =>
-        println(s"check failed for activations $activationIds: ${parsed}")
+        println(s"check failed for activations $activationIds: $parsed")
         throw error
     }
   }

-- 
To stop receiving notification emails like this one, please contact
cbickel@apache.org.