//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // we're going to store the received message in here
    $checkpoint = getCheckpoint();
    foreach (firstHostWithRole("zmq_target") as $hostId) {
        $context = usingZmqContext()->getZmqContext();
        $inPort = fromHost($hostId)->getStorySetting("zmq.single.inPort");
        $outPort = fromHost($hostId)->getStorySetting("zmq.single.outPort");
        $inSocket = usingZmqContext($context)->connectToHost($hostId, $inPort, 'PUSH');
        $outSocket = usingZmqContext($context)->connectToHost($hostId, $outPort, 'PULL');
        usingZmqSocket($inSocket)->send($checkpoint->expectedMessage);
        $checkpoint->actualMessage = fromZmqSocket($outSocket)->recv();
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    $checkpoint = getCheckpoint();
    assertsObject($checkpoint)->hasAttribute("expectedMessage");
    assertsObject($checkpoint)->hasAttribute("actualMessage");
    assertsString($checkpoint->actualMessage)->equals($checkpoint->expectedMessage);
});
// ------------------------------------------------------------------------
// ========================================================================
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // we're going to store the received message in here
    $checkpoint = getCheckpoint();
    foreach (firstHostWithRole("zmq_target") as $hostId) {
        // we need to connect
        $context = usingZmqContext()->getZmqContext();
        $inPort = fromHost($hostId)->getStorySetting("zmq.multi.inPort");
        $inSocket = usingZmqContext($context)->connectToHost($hostId, $inPort, 'PUSH');
        // now let's make sure we are connected
        expectsZmqSocket($inSocket)->isConnectedToHost($hostId, $inPort);
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // nothing to do
});