Menu

SObjectizer-5.5.24 and so_5_extra-1.2.2 Released!

SObjectizer has been updated to version 5.5.24 and so_5_extra has been updated to version 1.2.2.

The main new feature of SObjectizer-5.5.24 is an experimental support of unit-testing of agents.

The checking of agents' correctness was a hard question for a long time. There was no help from SObjectizer and every developer had to find the answer by him/herself. But starting from v.5.5.24 SObjectizer contains tools those allows to write unit-tests for agents.

Let's suppose we have Pinger agent that sends a Ping message to Ponger agent. There is also Ponger agent that replies with Pong message. Source code of those agents can be seen here.

An unit-test for checking Pinger and Ponger agents can looks like that way (doctest is used as unit-testing framework):

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

#include <ping_pong/agents.hpp>

#include <so_5/experimental/testing.hpp>

namespace tests = so_5::experimental::testing;

TEST_CASE( "ping_pong" )
{
    // Create an instance of special "testing" SObjectizer Environment.
    // SObjectizer will be started and stopped automatically. 
    tests::testing_env_t sobj;

    // We have to create and register agents to be tested.
    // We need pointers to agents to be used in testing scenario.
    pinger_t * pinger{};
    ponger_t * ponger{};
    sobj.environment().introduce_coop([&](so_5::coop_t & coop) {
        pinger = coop.make_agent< pinger_t >();
        ponger = coop.make_agent< ponger_t >();

        pinger->set_target( ponger->so_direct_mbox() );
        ponger->set_target( pinger->so_direct_mbox() );
    });

    // Start definition of the testing scenario.
    // The scenario will contain two steps.

    // We expect that Ponger will receive and handle Ping message on the first step.
    sobj.scenario().define_step("ping")
        .when(*ponger & tests::reacts_to<ping>());

    // We expect that Pinger will receive and handle Pong message on the second step.
    sobj.scenario().define_step("pong")
        .when(*pinger & tests::reacts_to<pong>());

    // The scenario is defined now.
    // Run it and wait no more than 100ms for completion.
    sobj.scenario().run_for(std::chrono::milliseconds(100));

    // Check for completion of the scenario.
    REQUIRE(tests::completed() == sobj.scenario().result());
}

More detailed information about this new feature can be found in the official project blog.

It is important to say that it is the very first version of support for unit-testing of agents. Obviously this support can be better. So we ask you to try the new functionality and give your feedback to us: what do you like, what you don't like, maybe we miss something?

You can provide your feedback to info at stiffstream point com or you can create a topic in the corresponding SourceForge sections (Discussion or Feature Requests) or you can create an issue on GitHub.

SObjectizer can be downloaded from Files section or can be checked out from GitHub-mirror. SObjectizer can also be obtained via vcpkg or Conan.

We also updated companion project so_5_extra: new versions of dependencies are used and yet another example was added.

so_5_extra can be downloaded from Files section. so_5_extra can also be obtained via vcpkg or Conan.

Posted by Yauheni Akhotnikau 2019-01-10

Log in to post a comment.