markusthoemmes commented on a change in pull request #2795: enable concurrent 
activation processing
URL: 
https://github.com/apache/incubator-openwhisk/pull/2795#discussion_r193307939
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala
 ##########
 @@ -383,6 +387,97 @@ class ContainerProxyTests
     }
   }
 
+  //This tests concurrency from the ContainerPool perspective - where multiple 
Run messages may be sent to ContainerProxy
+  //without waiting for the completion of the previous Run message (signaled 
by NeedWork message)
+  //Multiple messages can only be handled after Warming.
+  it should "stay in Running state if others are still running" in 
within(timeout) {
+    val initPromise = Promise[Interval]()
+    val runPromises = Seq(
+      Promise[(Interval, ActivationResponse)](),
+      Promise[(Interval, ActivationResponse)](),
+      Promise[(Interval, ActivationResponse)](),
+      Promise[(Interval, ActivationResponse)]())
+    val container = new TestContainer(Some(initPromise), Some(runPromises))
+    val factory = createFactory(Future.successful(container))
+    val acker = createAcker()
+    val store = createStore
+    val collector = createCollector()
+
+    val machine =
+      childActorOf(
+        ContainerProxy
+          .props(factory, acker, store, collector, InstanceId(0), poolConfig, 
pauseGrace = timeout))
+    registerCallback(machine)
+    preWarm(machine) //ends in Started state
+
+    machine ! Run(action, message) //first in Started state
+    machine ! Run(action, message) //second in Started or Running state
+
+    //first message go from Started -> Running -> Ready, with 2 NeedWork 
messages (1 for init, 1 for run)
+    //second message will be delayed until we get to Running state with 
WarmedData
+    //   (and will produce 1 NeedWork message after run)
+    expectMsg(Transition(machine, Started, Running))
+
+    //complete the init
+    initPromise complete Try(initInterval)
+    expectWarmed(invocationNamespace.name, action, 1) //when init completes
+
+    //complete the first run
+    runPromises(0) complete Try(runInterval, ActivationResponse.success())
+    expectWarmed(invocationNamespace.name, action, 0) //when first completes 
(count is 0 since stashed not counted)
+    expectMsg(Transition(machine, Running, Ready)) //wait for first to 
complete to skip the delay step that can only reliably be tested in single 
threaded
+    expectMsg(Transition(machine, Ready, Running)) //when second starts (after 
delay...)
+
+    //complete the second run
+    runPromises(1) complete Try(runInterval, ActivationResponse.success())
+    expectWarmed(invocationNamespace.name, action, 0) //when second completes
+
+    //go back to ready after first and second runs are complete
+    expectMsg(Transition(machine, Running, Ready))
+
+    machine ! Run(action, message) //third in Ready state
+    machine ! Run(action, message) //fourth in Ready state
+
+    //third message will go from Ready -> Running -> Ready (after fourth run)
+    expectMsg(Transition(machine, Ready, Running))
+
+    //complete the third run
+    runPromises(2) complete Try(runInterval, ActivationResponse.success())
+    expectWarmed(invocationNamespace.name, action, 1) //when third completes 
(stays in running)
+
+    //complete the fourth run
+    runPromises(3) complete Try(runInterval, ActivationResponse.success())
+    expectWarmed(invocationNamespace.name, action, 0) //when fourth completes
+
+    //back to ready
+    expectMsg(Transition(machine, Running, Ready))
+
+    //timeout + pause after getting back to Ready
+    timeout(machine)
+    expectMsg(Transition(machine, Ready, Pausing))
+    expectMsg(Transition(machine, Pausing, Paused))
+
+    awaitAssert {
+      factory.calls should have size 1
+      container.initializeCount shouldBe 1
+      container.runCount shouldBe 4
+      collector.calls should have size 4
+      container.suspendCount shouldBe 1
+      container.resumeCount shouldBe 0
+      acker.calls should have size 4
+      store.calls should have size 4
+      acker
+        .calls(0)
+        ._2
+        .annotations
+        .get(WhiskActivation.initTimeAnnotation)
+        .get
+        .convertTo[Int] shouldBe initInterval.duration.toMillis
+      acker.calls(1)._2.annotations.get(WhiskActivation.initTimeAnnotation) 
shouldBe empty
+    }
+
+  }
 
 Review comment:
   Nice test 👍 

----------------------------------------------------------------
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