Skip to content

Strange behavior of so_set_delivery_state #108

Description

@Bobrov88

I use So_5 in my project with tests.
Please, explain me, why.

Here my Agent:


void Agent::so_define_agent()
{
    so_subscribe_self()
        .event(&Agent::onDlStarted)
        .event(&Agent::onUlStarted)
        .event(&Agent::onDlStopped)
        .event(&Agent::onUlStopped);

// bool m_isUlStartedAllowed = true;
// bool m_isDlStartedAllowed= true;

    so_set_delivery_filter(so_direct_mbox(), [this](const UlStarted&) { return m_isUlStartedAllowed; });
    so_set_delivery_filter(so_direct_mbox(), [this](const DlStarted&) { return m_isDlStartedAllowed; });
}

void Agent::onDlStarted(so_5::mhood_t<DlStarted> msg)
{
    // some actions
    m_isDlStartedAllowed = false;
    std::cout << " !!!!!!!!!!!!!!!!!!!!!!!      onDl"; // for tests
}

void Agent::onlStarted(so_5::mhood_t<UlStarted> msg)
{
   // some actions
    m_isUlStartedAllowed = false;
    std::cout << " !!!!!!!!!!!!!!!!!!!!!!!      onUl";  //for tests
}

void Agent::onDlStopped(so_5::mhood_t<DlStopped> cmd)
{
   // some actions
    m_isDlStartedAllowed = true;
    std::cout << " !!!!!!!!!!!!!!!!!!!!!!!      onDl STOP";  // for tests
}

void Agent::onUlStopped(so_5::mhood_t<UlStopped> cmd)
{
    m_isUlStartedAllowed = true;
    std::cout << " !!!!!!!!!!!!!!!!!!!!!!!      onUl STOP";  // for tests
}



Look at the test:

    void testUlStartedAndStopped()
    {
        suppressWarnings();

// first UlStarted send - flag --> false
        m_testEnv.scenario()
            .define_step("::UlStarted #1")
            .impact<UlStarted>(*m_agent)
            .when(*m_agent & tests::reacts_to<UlStarted>());

//  send - flag --> true
        m_testEnv.scenario()
            .define_step("::UlStopped")
            .impact<UlStopped>(*m_agent)
            .when(*m_agent & tests::reacts_to<UlStopped>());

// second UlStarted send - flag --> false
        m_testEnv.scenario()
            .define_step("::UlStarted #2")
            .impact<UlStarted>(*m_agent)
            .when(*m_agent & tests::reacts_to<PhyUlStarted>());

// third UlStarted send - delivery filter must work
        m_testEnv.scenario()
            .define_step("::UlStarted #3")
            .impact<UlStarted>(*m_agent)
            .when(*m_agent & tests::reacts_to<UlStarted>());

        m_testEnv.scenario().run_for(200ms);
        m_testEnv.stop_then_join();

        auto result = m_testEnv.scenario().result();

        EXPECT_NE(tests::completed(), result);

        std::stringstream ss;
        ss << result;
        std::string scheme = ss.str();

        EXPECT_EQ(scheme.find("::UlStarted #1"), std::string::npos);
        EXPECT_EQ(scheme.find("::UlStopped"), std::string::npos);
        EXPECT_EQ(scheme.find("::UlStarted #2"), std::string::npos);
        EXPECT_NE(scheme.find("::UlStarted #3"), std::string::npos);
    }


Look at test result:



[       OK ]AgentTests.TestDlStartedAndStopped (3 ms)
[ RUN      ] AgentTests.TestUlStartedAndStopped
 !!!!!!!!!!!!!!!!!!!!!!!      onUl                           <----------------------------
 !!!!!!!!!!!!!!!!!!!!!!!      onUl STOP.                <----------------------------

    // WHERE IS THE REST?? FLAG IS TRUE. WHY IS NOT HANDLED?

./AgentTests.cpp:460: Failure
Expected equality of these values:
  scheme.find("::UlStarted #2")
    Which is: 30
  std::string::npos
    Which is: 18446744073709551615

../AgentTests.cpp:461: Failure

I used to try with drop_subscription/so_subsribe_self as analog of flag bool/true, but it doesn't work.
Did you get the point? I can explain if you don't
Thanx!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions