Skip to content

Commit

Permalink
update ContainerProxy tests to exercise "concurrent" Run messages (wi…
Browse files Browse the repository at this point in the history
…thout waiting for previous Run message to complete)
  • Loading branch information
tysonnorris committed Apr 25, 2018
1 parent 90e993c commit 63c4aa8
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,67 @@ 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 container = new TestContainer
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
machine ! Run(action, message) //third in Started or Running state
machine ! Run(action, message) //fourth in Started or Running state

expectMsg(Transition(machine, Started, Running))

//first message runs alone to go from Started -> Running -> Ready
expectWarmed(invocationNamespace.name, action)
expectMsg(Transition(machine, Running, Ready))

//second, third, fourth messages run without intermediate Ready states (stays in Running state):
// Ready -> Running -> NeedWork -> NeedWork -> NeedWork -> Ready
expectMsg(Transition(machine, Ready, Running))
expectWarmed(invocationNamespace.name, action)
expectWarmed(invocationNamespace.name, action)
expectWarmed(invocationNamespace.name, action)
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
}

}

/*
* ERROR CASES
*/
Expand Down

0 comments on commit 63c4aa8

Please sign in to comment.