openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csantan...@apache.org
Subject [incubator-openwhisk] branch master updated: Delete test assets. (#2826)
Date Wed, 04 Oct 2017 01:17:35 GMT
This is an automated email from the ASF dual-hosted git repository.

csantanapr 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 30aa711  Delete test assets. (#2826)
30aa711 is described below

commit 30aa7115275f9a9ae5b50fe20809ad98cab36a31
Author: rodric rabbah <rodric@gmail.com>
AuthorDate: Tue Oct 3 21:17:33 2017 -0400

    Delete test assets. (#2826)
---
 .../src/test/scala/ha/CacheInvalidationTests.scala | 32 ++++++++++++--------
 .../whisk/core/cli/test/WskEntitlementTests.scala  | 16 +++++-----
 .../controller/test/PackageActionsApiTests.scala   |  5 ++--
 .../core/controller/test/SequenceApiTests.scala    | 35 ++++++++++++++--------
 .../SequenceActionApiMigrationTests.scala          |  2 ++
 .../scala/whisk/core/database/test/DbUtils.scala   |  8 +++++
 6 files changed, 64 insertions(+), 34 deletions(-)

diff --git a/tests/src/test/scala/ha/CacheInvalidationTests.scala b/tests/src/test/scala/ha/CacheInvalidationTests.scala
index 39ee052..59bc36d 100644
--- a/tests/src/test/scala/ha/CacheInvalidationTests.scala
+++ b/tests/src/test/scala/ha/CacheInvalidationTests.scala
@@ -46,12 +46,14 @@ class CacheInvalidationTests extends FlatSpec with Matchers with WskTestHelpers
   implicit val materializer = ActorMaterializer()
 
   val hosts = WhiskProperties.getProperty("controller.hosts").split(",")
+
   def ports(instance: Int) = WhiskProperties.getControllerBasePort + instance
 
   def controllerUri(instance: Int) = {
     require(instance >= 0 && instance < hosts.length, "Controller instance
not known.")
     Uri().withScheme("http").withHost(hosts(instance)).withPort(ports(instance))
   }
+
   def actionPath(name: String) = Uri.Path(s"/api/v1/namespaces/_/actions/$name")
 
   val Array(username, password) = WhiskProperties.readAuthKey(WhiskProperties.getAuthFileForTesting).split(":")
@@ -135,21 +137,25 @@ class CacheInvalidationTests extends FlatSpec with Matchers with WskTestHelpers
       deleteAction(actionName, 0, None)
       deleteAction(actionName, 1, None)
 
-      // Create an action on controller0
-      val createdAction = updateAction(actionName, "CODE_CODE_CODE", 0)
+      try {
+        // Create an action on controller0
+        val createdAction = updateAction(actionName, "CODE_CODE_CODE", 0)
 
-      // Get action from controller1
-      val actionFromController1 = getAction(actionName, 1)
-      createdAction shouldBe actionFromController1
-
-      // Update the action on controller0
-      val updatedAction = updateAction(actionName, "CODE_CODE", 0)
-
-      retry({
         // Get action from controller1
-        val updatedActionFromController1 = getAction(actionName, 1)
-        updatedAction shouldBe updatedActionFromController1
-      })
+        val actionFromController1 = getAction(actionName, 1)
+        createdAction shouldBe actionFromController1
+
+        // Update the action on controller0
+        val updatedAction = updateAction(actionName, "CODE_CODE", 0)
+
+        retry({
+          // Get action from controller1
+          val updatedActionFromController1 = getAction(actionName, 1)
+          updatedAction shouldBe updatedActionFromController1
+        })
+      } finally {
+        deleteAction(actionName, 0, None)
+      }
     }
 
     it should "be invalidated on deleting an entity" in {
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
index 28e1b5b..cd58feb 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskEntitlementTests.scala
@@ -70,6 +70,7 @@ class WskEntitlementTests extends TestHelpers with WskTestHelpers with BeforeAnd
           rr.stderr should include("not authorized")
           rr
         }
+
         assetHelper.withCleaner(wsk.action, "unauthorized sequence", confirmDelete = false)
{ (action, name) =>
           val rr = action.create(
             name,
@@ -271,16 +272,17 @@ class WskEntitlementTests extends TestHelpers with WskTestHelpers with
BeforeAnd
   it should "not allow invoke an action sequence with more than one component from package
after entitlement change" in withAssetCleaner(
     guestWskProps) { (guestwp, assetHelper) =>
     val privateSamplePackage = samplePackage + "prv"
-    assetHelper.withCleaner(wsk.pkg, samplePackage) { (pkg, _) =>
-      pkg.create(samplePackage, parameters = Map("a" -> "A".toJson), shared = Some(true))(guestwp)
-      pkg.create(privateSamplePackage, parameters = Map("a" -> "A".toJson), shared = Some(true))(guestwp)
+    Seq(samplePackage, privateSamplePackage).foreach { n =>
+      assetHelper.withCleaner(wsk.pkg, n) { (pkg, _) =>
+        pkg.create(n, parameters = Map("a" -> "A".toJson), shared = Some(true))(guestwp)
+      }
     }
 
-    assetHelper.withCleaner(wsk.action, fullSampleActionName) {
+    Seq(fullSampleActionName, s"$privateSamplePackage/$sampleAction").foreach { a =>
       val file = Some(TestUtils.getTestActionFilename("hello.js"))
-      (action, _) =>
-        action.create(fullSampleActionName, file)(guestwp)
-        action.create(s"$privateSamplePackage/$sampleAction", file)(guestwp)
+      assetHelper.withCleaner(wsk.action, a) { (action, _) =>
+        action.create(a, file)(guestwp)
+      }
     }
 
     withAssetCleaner(defaultWskProps) { (dwp, assetHelper) =>
diff --git a/tests/src/test/scala/whisk/core/controller/test/PackageActionsApiTests.scala
b/tests/src/test/scala/whisk/core/controller/test/PackageActionsApiTests.scala
index 6015aab..24d19b6 100644
--- a/tests/src/test/scala/whisk/core/controller/test/PackageActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/PackageActionsApiTests.scala
@@ -556,7 +556,6 @@ class PackageActionsApiTests extends ControllerTestCommon with WhiskActionsApi
{
     val entity = BadEntity(provider.namespace.addPath(provider.name), aname())
     put(entityStore, provider)
     put(entityStore, entity)
-
     Delete(s"$collectionPath/${provider.name}/${entity.name}") ~> Route.seal(routes(creds))
~> check {
       responseAs[ErrorResponse].error shouldBe Messages.corruptedEntity
     }
@@ -567,9 +566,11 @@ class PackageActionsApiTests extends ControllerTestCommon with WhiskActionsApi
{
     val provider = WhiskPackage(namespace, aname())
     val entity = BadEntity(provider.fullPath, aname())
     put(entityStore, provider, false)
-    put(entityStore, entity, false)
+    val entityToDelete = put(entityStore, entity, false)
 
     Delete(s"$collectionPath/${provider.name}/${entity.name}") ~> Route.seal(routes(creds))
~> check {
+      deletePackage(provider.docid)
+      delete(entityStore, entityToDelete)
       status should be(InternalServerError)
       responseAs[ErrorResponse].error shouldBe Messages.corruptedEntity
     }
diff --git a/tests/src/test/scala/whisk/core/controller/test/SequenceApiTests.scala b/tests/src/test/scala/whisk/core/controller/test/SequenceApiTests.scala
index 05d046c..56af3a8 100644
--- a/tests/src/test/scala/whisk/core/controller/test/SequenceApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/SequenceApiTests.scala
@@ -48,7 +48,9 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
   val creds = WhiskAuthHelpers.newIdentity()
   val namespace = EntityPath(creds.subject.asString)
   val defaultNamespace = EntityPath.DEFAULT
+
   def aname() = MakeName.next("sequence_tests")
+
   val allowedActionDuration = 120 seconds
 
   it should "reject creation of sequence with more actions than allowed limit" in {
@@ -161,12 +163,13 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
     }
 
     // now create exec sequence with a self-reference
-    val seqNameWithNamespace = stringToFullyQualifiedName(s"/${namespace}/${seqName.name}")
+    val seqNameWithNamespace = stringToFullyQualifiedName(s"/$namespace/${seqName.name}")
     val updatedSeq = components.updated(1, seqNameWithNamespace)
     val updatedContent = WhiskActionPut(Some(sequence(updatedSeq.toVector)))
 
     // update the sequence
     Put(s"$collectionPath/${seqName.name}?overwrite=true", updatedContent) ~> Route.seal(routes(creds))
~> check {
+      deleteAction(DocId(s"$namespace/${seqName.name}"))
       status should be(BadRequest)
       responseAs[ErrorResponse].error shouldBe Messages.sequenceIsCyclic
     }
@@ -185,6 +188,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
 
     // create an action sequence
     Put(s"$collectionPath/${seqName.name}", content) ~> Route.seal(routes(creds)) ~>
check {
+      deleteAction(DocId(s"$namespace/${seqName.name}"))
       status should be(OK)
     }
   }
@@ -215,6 +219,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
 
     // create an action sequence
     Put(s"$collectionPath/${seqName.name}", content) ~> Route.seal(routes(creds)) ~>
check {
+      deleteAction(DocId(s"$namespace/${seqName.name}"))
       status should be(OK)
       val response = responseAs[String]
     }
@@ -253,6 +258,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
 
     // update the sequence
     Put(s"$collectionPath/$pkg/${seqName.name}?overwrite=true", updatedContent) ~> Route.seal(routes(creds))
~> check {
+      deleteAction(DocId(s"$namespace/$pkg/${seqName.name}"))
       status should be(BadRequest)
       responseAs[ErrorResponse].error shouldBe Messages.sequenceIsCyclic
     }
@@ -299,6 +305,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
 
     Console.withOut(stream) {
       Put(s"$collectionPath/$sSeqName", content) ~> Route.seal(routes(creds)) ~> check
{
+        deleteAction(sSeq.docid)
         status should be(OK)
         logContains(s"atomic action count ${2 * actionCnt}")(stream)
       }
@@ -333,7 +340,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
     // make sequence x and install it in db
     putSimpleSequenceInDB(xAct, namespace, xComp)
     val sAct = s"${aname()}_s"
-    val sSeq = makeSimpleSequence(sAct, namespace, Vector(s"$aAct", s"$xAct", s"$yAct"),
false) // a, x, y  in the db already
+    val sSeq = makeSimpleSequence(sAct, namespace, Vector(aAct, xAct, yAct), false) // a,
x, y  in the db already
     // create an action sequence s
     val content = WhiskActionPut(Some(sSeq.exec))
 
@@ -346,7 +353,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
     }
 
     // update action z to point to s --- should be rejected
-    val zUpdate = makeSimpleSequence(zAct, namespace, Vector(s"$sAct"), false) // s in the
db already
+    val zUpdate = makeSimpleSequence(zAct, namespace, Vector(sAct), false) // s in the db
already
     val zUpdateContent = WhiskActionPut(Some(zUpdate.exec))
     Put(s"$collectionPath/$zAct?overwrite=true", zUpdateContent) ~> Route.seal(routes(creds))
~> check {
       status should be(BadRequest)
@@ -354,7 +361,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
     }
 
     // update action s to point to a, s, b --- should be rejected
-    val sUpdate = makeSimpleSequence(sAct, namespace, Vector(s"$aAct", s"$sAct", s"$bAct"),
false) // s in the db already
+    val sUpdate = makeSimpleSequence(sAct, namespace, Vector(aAct, sAct, bAct), false) //
s in the db already
     val sUpdateContent = WhiskActionPut(Some(sUpdate.exec))
     Put(s"$collectionPath/$sAct?overwrite=true", sUpdateContent) ~> Route.seal(routes(creds))
~> check {
       status should be(BadRequest)
@@ -362,7 +369,7 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
     }
 
     // update action z to point to y
-    val zSeq = makeSimpleSequence(zAct, namespace, Vector(s"$yAct"), false) // y  in the
db already
+    val zSeq = makeSimpleSequence(zAct, namespace, Vector(yAct), false) // y  in the db already
     val updateContent = WhiskActionPut(Some(zSeq.exec))
     stream.reset()
     Console.withOut(stream) {
@@ -372,11 +379,13 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
       logContains("atomic action count 1")(stream)
     }
     // update sequence s to s -> a, x, y, a, b
-    val newS = makeSimpleSequence(sAct, namespace, Vector(s"$aAct", s"$xAct", s"$yAct", s"$aAct",
s"$bAct"), false) // a, x, y, b  in the db already
+    val newS = makeSimpleSequence(sAct, namespace, Vector(aAct, xAct, yAct, aAct, bAct),
false) // a, x, y, b  in the db already
     val newSContent = WhiskActionPut(Some(newS.exec))
     stream.reset()
     Console.withOut(stream) {
       Put(s"${collectionPath}/$sAct?overwrite=true", newSContent) ~> Route.seal(routes(creds))
~> check {
+        deleteAction(sSeq.docid)
+        deleteAction(zSeq.docid)
         status should be(OK)
       }
       logContains("atomic action count 6")(stream)
@@ -388,8 +397,8 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
    * All actions are in the default package.
    *
    * @param sequenceName the name of the sequence
-   * @param ns the namespace to be used when creating the component actions and the sequence
action
-   * @param components the names of the actions (entity names, no namespace)
+   * @param ns           the namespace to be used when creating the component actions and
the sequence action
+   * @param components   the names of the actions (entity names, no namespace)
    */
   private def putSimpleSequenceInDB(sequenceName: String, ns: EntityPath, components: Vector[String])(
     implicit tid: TransactionId) = {
@@ -402,10 +411,10 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
    * If instructed to do so, installs the component actions in the db.
    * All actions are in the default package.
    *
-   * @param sequenceName the name of the sequence
-   * @param ns the namespace to be used when creating the component actions and the sequence
action
+   * @param sequenceName   the name of the sequence
+   * @param ns             the namespace to be used when creating the component actions and
the sequence action
    * @param componentNames the names of the actions (entity names, no namespace)
-   * @param installDB if true, installs the component actions in the db (default true)
+   * @param installDB      if true, installs the component actions in the db (default true)
    */
   private def makeSimpleSequence(sequenceName: String,
                                  ns: EntityPath,
@@ -417,7 +426,9 @@ class SequenceApiTests extends ControllerTestCommon with WhiskActionsApi
{
         WhiskAction(ns, EntityName(c), jsDefault("??"))
       }
       // add them to the db
-      wskActions.foreach { put(entityStore, _) }
+      wskActions.foreach {
+        put(entityStore, _)
+      }
     }
     // add namespace to component names
     val components = componentNames map { c =>
diff --git a/tests/src/test/scala/whisk/core/controller/test/migration/SequenceActionApiMigrationTests.scala
b/tests/src/test/scala/whisk/core/controller/test/migration/SequenceActionApiMigrationTests.scala
index 17d510d..4d0f035 100644
--- a/tests/src/test/scala/whisk/core/controller/test/migration/SequenceActionApiMigrationTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/migration/SequenceActionApiMigrationTests.scala
@@ -169,7 +169,9 @@ class SequenceActionApiMigrationTests
 
     // update an action sequence
     Put(s"$collectionPath/${seqName}?overwrite=true", content) ~> Route.seal(routes(creds))
~> check {
+      deleteAction(seqAction.docid)
       status should be(OK)
+
       val response = responseAs[WhiskAction]
       response.exec.kind should be(Exec.SEQUENCE)
       response.limits should be(seqAction.limits)
diff --git a/tests/src/test/scala/whisk/core/database/test/DbUtils.scala b/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
index d487611..a01e04f 100644
--- a/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
+++ b/tests/src/test/scala/whisk/core/database/test/DbUtils.scala
@@ -206,6 +206,14 @@ trait DbUtils extends TransactionCounter {
   }
 
   /**
+   * Deletes document by id and revision from datastore.
+   */
+  def delete(db: ArtifactStore[_], docinfo: DocInfo)(implicit transid: TransactionId,
+                                                     timeout: Duration = 10 seconds) = {
+    Await.result(db.del(docinfo), timeout)
+  }
+
+  /**
    * Puts a document 'entity' into the datastore, then do a get to retrieve it and confirm
the identity.
    */
   def putGetCheck[A, Au >: A](db: ArtifactStore[Au], entity: A, factory: DocumentFactory[A],
gc: Boolean = true)(

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Mime
View raw message