dubeejw closed pull request #3121: Enforce WhiskAction equality mod DocRevision.
URL: https://github.com/apache/incubator-openwhisk/pull/3121
 
 
   

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/common/scala/src/main/scala/whisk/core/connector/Message.scala 
b/common/scala/src/main/scala/whisk/core/connector/Message.scala
index c7cff9fbdb..d79ba267ae 100644
--- a/common/scala/src/main/scala/whisk/core/connector/Message.scala
+++ b/common/scala/src/main/scala/whisk/core/connector/Message.scala
@@ -58,15 +58,6 @@ case class ActivationMessage(override val transid: 
TransactionId,
                              cause: Option[ActivationId] = None)
     extends Message {
 
-  def meta =
-    JsObject("meta" -> {
-      cause map { c =>
-        JsObject(c.toJsObject.fields ++ activationId.toJsObject.fields)
-      } getOrElse {
-        activationId.toJsObject
-      }
-    })
-
   override def serialize = ActivationMessage.serdes.write(this).compactPrint
 
   override def toString = {
diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala 
b/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
index afd85cc395..4aaddbd7e0 100644
--- a/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
@@ -216,6 +216,11 @@ case class WhiskActionMetaData(namespace: EntityPath,
  *
  * exec is typed to CodeExec to guarantee executability by an Invoker.
  *
+ * Note: Two actions are equal regardless of their DocRevision if there is one.
+ * The invoker uses action equality when matching actions to warm containers.
+ * That means creating an action, invoking it, then 
deleting/recreating/reinvoking
+ * it will reuse the previous container. The delete/recreate restores the 
SemVer to 0.0.1.
+ *
  * @param namespace the namespace for the action
  * @param name the name of the action
  * @param exec the action executable details
diff --git 
a/tests/src/test/scala/whisk/core/containerpool/test/ContainerPoolTests.scala 
b/tests/src/test/scala/whisk/core/containerpool/test/ContainerPoolTests.scala
index a607f5ba06..dcfe5e404c 100644
--- 
a/tests/src/test/scala/whisk/core/containerpool/test/ContainerPoolTests.scala
+++ 
b/tests/src/test/scala/whisk/core/containerpool/test/ContainerPoolTests.scala
@@ -90,6 +90,7 @@ class ContainerPoolTests
 
   val runMessage = createRunMessage(action, invocationNamespace)
   val runMessageDifferentAction = createRunMessage(differentAction, 
invocationNamespace)
+  val runMessageDifferentVersion = 
createRunMessage(action.copy().revision(DocRevision("v2")), invocationNamespace)
   val runMessageDifferentNamespace = createRunMessage(action, 
differentInvocationNamespace)
   val runMessageDifferentEverything = createRunMessage(differentAction, 
differentInvocationNamespace)
 
@@ -133,6 +134,20 @@ class ContainerPoolTests
     containers(1).expectNoMsg(100.milliseconds)
   }
 
+  it should "reuse a warm container when action is the same even if revision 
changes" in within(timeout) {
+    val (containers, factory) = testContainers(2)
+    val feed = TestProbe()
+    val pool = system.actorOf(ContainerPool.props(factory, 2, 2, feed.ref))
+
+    pool ! runMessage
+    containers(0).expectMsg(runMessage)
+    containers(0).send(pool, NeedWork(warmedData()))
+
+    pool ! runMessageDifferentVersion
+    containers(0).expectMsg(runMessageDifferentVersion)
+    containers(1).expectNoMsg(100.milliseconds)
+  }
+
   it should "create a container if it cannot find a matching container" in 
within(timeout) {
     val (containers, factory) = testContainers(2)
     val feed = TestProbe()
diff --git a/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala 
b/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala
index dd3fa042a4..504db38c0e 100644
--- a/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala
+++ b/tests/src/test/scala/whisk/core/entity/test/SchemaTests.scala
@@ -26,17 +26,16 @@ import scala.language.postfixOps
 import scala.language.reflectiveCalls
 import scala.util.Failure
 import scala.util.Try
-
 import org.junit.runner.RunWith
 import org.scalatest.BeforeAndAfter
 import org.scalatest.FlatSpec
 import org.scalatest.Matchers
 import org.scalatest.junit.JUnitRunner
-
 import spray.json._
 import spray.json.DefaultJsonProtocol._
 import whisk.core.controller.test.WhiskAuthHelpers
 import whisk.core.entitlement.Privilege
+import whisk.core.entity.ExecManifest.{ImageName, RuntimeManifest}
 import whisk.core.entity._
 import whisk.core.entity.size.SizeInt
 import whisk.http.Messages
@@ -469,6 +468,26 @@ class SchemaTests extends FlatSpec with BeforeAndAfter 
with ExecHelpers with Mat
     }
   }
 
+  it should "compare as equal two actions even if their revision does not 
match" in {
+    val exec = CodeExecAsString(RuntimeManifest("actionKind", 
ImageName("testImage")), "testCode", None)
+    val actionA = WhiskAction(EntityPath("actionSpace"), 
EntityName("actionName"), exec)
+    val actionB = actionA.copy()
+    val actionC = actionA.copy()
+    actionC.revision(DocRevision("2"))
+    actionA shouldBe actionB
+    actionA shouldBe actionC
+  }
+
+  it should "compare as equal two executable actions even if their revision 
does not match" in {
+    val exec = CodeExecAsString(RuntimeManifest("actionKind", 
ImageName("testImage")), "testCode", None)
+    val actionA = ExecutableWhiskAction(EntityPath("actionSpace"), 
EntityName("actionName"), exec)
+    val actionB = actionA.copy()
+    val actionC = actionA.copy()
+    actionC.revision(DocRevision("2"))
+    actionA shouldBe actionB
+    actionA shouldBe actionC
+  }
+
   it should "reject malformed JSON" in {
     val b64 = Base64.getEncoder()
     val contents = b64.encodeToString("tarball".getBytes)


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to