You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2018/03/02 22:30:41 UTC

[incubator-openwhisk] branch master updated: Sanitize test subjects before tests. (#3302)

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

dubeejw 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 f7efbb6  Sanitize test subjects before tests. (#3302)
f7efbb6 is described below

commit f7efbb6cf09563009b71486158b9232433439660
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Fri Mar 2 17:30:38 2018 -0500

    Sanitize test subjects before tests. (#3302)
    
    * Sanitize test subjects before tests.
---
 tests/src/test/scala/common/WskTestHelpers.scala |  5 ++--
 tests/src/test/scala/limits/ThrottleTests.scala  | 30 ++++++++++++++++--------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/tests/src/test/scala/common/WskTestHelpers.scala b/tests/src/test/scala/common/WskTestHelpers.scala
index 5be175c..57a5442 100644
--- a/tests/src/test/scala/common/WskTestHelpers.scala
+++ b/tests/src/test/scala/common/WskTestHelpers.scala
@@ -31,6 +31,7 @@ import spray.json._
 import spray.json.DefaultJsonProtocol._
 
 import TestUtils.RunResult
+import TestUtils.SUCCESS_EXIT
 import TestUtils.CONFLICT
 import akka.http.scaladsl.model.StatusCodes
 
@@ -287,10 +288,10 @@ trait WskTestHelpers extends Matchers {
     WskProps(namespace = newUser, authKey = wskadmin.cli(Seq("user", "create", newUser)).stdout.trim)
   }
 
-  def disposeAdditionalTestSubject(subject: String): Unit = {
+  def disposeAdditionalTestSubject(subject: String, expectedExitCode: Int = SUCCESS_EXIT): Unit = {
     val wskadmin = new RunWskAdminCmd {}
     withClue(s"failed to delete temporary subject $subject") {
-      wskadmin.cli(Seq("user", "delete", subject)).stdout should include("Subject deleted")
+      wskadmin.cli(Seq("user", "delete", subject), expectedExitCode).stdout should include("Subject deleted")
     }
   }
 }
diff --git a/tests/src/test/scala/limits/ThrottleTests.scala b/tests/src/test/scala/limits/ThrottleTests.scala
index 9aee3fb..efeb909 100644
--- a/tests/src/test/scala/limits/ThrottleTests.scala
+++ b/tests/src/test/scala/limits/ThrottleTests.scala
@@ -25,14 +25,12 @@ import scala.collection.parallel.immutable.ParSeq
 import scala.concurrent.Future
 import scala.concurrent.Promise
 import scala.concurrent.duration._
-
 import org.junit.runner.RunWith
 import org.scalatest.BeforeAndAfterAll
 import org.scalatest.FlatSpec
 import org.scalatest.Matchers
 import org.scalatest.concurrent.ScalaFutures
 import org.scalatest.junit.JUnitRunner
-
 import common.RunWskAdminCmd
 import common.TestHelpers
 import common.TestUtils
@@ -48,6 +46,8 @@ import whisk.http.Messages._
 import whisk.utils.ExecutionContextFactory
 import whisk.utils.retry
 
+import scala.util.{Success, Try}
+
 protected[limits] trait LocalHelper {
   def prefix(msg: String) = msg.substring(0, msg.indexOf('('))
 }
@@ -298,10 +298,26 @@ class NamespaceSpecificThrottleTests
     with BeforeAndAfterAll
     with LocalHelper {
 
+  val defaultAction = Some(TestUtils.getTestActionFilename("hello.js"))
+
   val wskadmin = new RunWskAdminCmd {}
   val wsk = new WskRest
 
-  val defaultAction = Some(TestUtils.getTestActionFilename("hello.js"))
+  def sanitizeNamespaces(namespaces: Seq[String], expectedExitCode: Int = SUCCESS_EXIT): Unit = {
+    val deletions = namespaces.map { ns =>
+      Try {
+        disposeAdditionalTestSubject(ns, expectedExitCode)
+        withClue(s"failed to delete temporary limits for $ns") {
+          wskadmin.cli(Seq("limits", "delete", ns), expectedExitCode)
+        }
+      }
+    }
+    if (expectedExitCode == SUCCESS_EXIT) every(deletions) shouldBe a[Success[_]]
+  }
+
+  sanitizeNamespaces(
+    Seq("zeroSubject", "zeroConcSubject", "oneSubject", "oneSequenceSubject"),
+    expectedExitCode = DONTCARE_EXIT)
 
   // Create a subject with rate limits == 0
   val zeroProps = getAdditionalTestSubject("zeroSubject")
@@ -330,13 +346,7 @@ class NamespaceSpecificThrottleTests
   wskadmin.cli(Seq("limits", "set", oneSequenceProps.namespace, "--invocationsPerMinute", "1", "--firesPerMinute", "1"))
 
   override def afterAll() = {
-    Seq(zeroProps, zeroConcProps, oneProps, oneSequenceProps).foreach { wp =>
-      val ns = wp.namespace
-      disposeAdditionalTestSubject(ns)
-      withClue(s"failed to delete temporary limits for $ns") {
-        wskadmin.cli(Seq("limits", "delete", ns))
-      }
-    }
+    sanitizeNamespaces(Seq(zeroProps, zeroConcProps, oneProps, oneSequenceProps).map(_.namespace))
   }
 
   behavior of "Namespace-specific throttles"

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