dubeejw closed pull request #3302: Sanitize test subjects before tests. URL: https://github.com/apache/incubator-openwhisk/pull/3302
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 5be175c44b..57a5442ed8 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 9aee3fb6f1..efeb90976d 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" ---------------------------------------------------------------- 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