public function testQueueProcessAfterNonMultiYield() { $seq = 0; // there will be two callees //// Mocking $realm = $this->getMockBuilder('\\Thruway\\Realm')->setConstructorArgs(["theRealm"])->setMethods(["publishMeta"])->getMock(); $sessionMockBuilder = $this->getMockBuilder('\\Thruway\\Session')->setMethods(['sendMessage'])->disableOriginalConstructor(); $callee0Session = $sessionMockBuilder->getMock(); $callee1Session = $sessionMockBuilder->getMock(); $callerSession = $sessionMockBuilder->getMock(); $callee0Session->setRealm($realm); $callee1Session->setRealm($realm); $callerSession->setRealm($realm); //// End of Mocking $realm->expects($this->exactly(2))->method("publishMeta")->with($this->equalTo('thruway.metaevent.procedure.congestion'), $this->equalTo([["name" => "qpanmy_proc0"]])); $invocationIDs = []; $callee0Session->expects($this->exactly(6))->method("sendMessage")->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[0] = $value->getRequestId(); return true; })], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[1] = $value->getRequestId(); return true; })], [$this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')], [$this->callback(function ($value) use(&$invocationIDs) { $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[2] = $value->getRequestId(); return true; })], [$this->callback(function ($value) use(&$invocationIDs) { // invocation after yield $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $value); $invocationIDs[3] = $value->getRequestId(); return true; })]); // create a dealer $dealer = new \Thruway\Role\Dealer(); // register proc0 as multi $registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), ["thruway_multiregister" => true], "qpanmy_proc0"); $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($callee0Session, $registerMsg)); $callMsg = new \Thruway\Message\CallMessage(\Thruway\Common\Utils::getUniqueId(), [], "qpanmy_proc0"); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callMsg)); $callMsg->setRequestId(\Thruway\Common\Utils::getUniqueId()); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callMsg)); $yieldMsg = new \Thruway\Message\YieldMessage($invocationIDs[0], []); $dealer->handleYieldMessage(new \Thruway\Event\MessageEvent($callee0Session, $yieldMsg)); $yieldMsg = new \Thruway\Message\YieldMessage($invocationIDs[1], []); $dealer->handleYieldMessage(new \Thruway\Event\MessageEvent($callee0Session, $yieldMsg)); // there are now zero calls on proc0 $registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), [], "qpanmy_proc1"); $callProc1Msg = new \Thruway\Message\CallMessage(\Thruway\Common\Utils::getUniqueId(), [], "qpanmy_proc1"); $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($callee0Session, $registerMsg)); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callProc1Msg)); // this should cause congestion and queuing because it should be busy with proc1 $callMsg->setRequestId(\Thruway\Common\Utils::getUniqueId()); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callMsg)); // yield on proc1 - this should cause proc0 to process queue $yieldMsg = new \Thruway\Message\YieldMessage($invocationIDs[2], []); $dealer->handleYieldMessage(new \Thruway\Event\MessageEvent($callee0Session, $yieldMsg)); }