cbickel closed pull request #3303: Actually retry package remove on conflict. URL: https://github.com/apache/incubator-openwhisk/pull/3303
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/tests/src/test/scala/common/WskTestHelpers.scala b/tests/src/test/scala/common/WskTestHelpers.scala index c9073f60a6..dbd03ca2f2 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 } } ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services