Closed JorgenPo closed 2 years ago
Hi!
I'll take some time to think about your case.
It looks like the problem is the absence of any test scenario steps in your test case. You just create a parent coop and then run an empty test scenario by calling run_for
method. Because the test scenario is empty the work of the test environment will be finished. It's an asynchronous process that is executed in the background and takes some time. But when you call run_for
there is another activity on some worker thread: execution of TestAgent's so_evt_start
. And that execution is going in parallel with the shutdown operation. That is why you can't register new cooperation and got the exception.
Please note that agents created in testing.environment().introduce_coop()
are frozen until run_for
is called. There is an explanation: https://github.com/Stiffstream/sobjectizer/wiki/SO-5.7-Experimental-Testing#a-test-case-for-pingerponger
When testing_env_t is used all agents are frozen after the registration if the testing scenario is not started yet. This means that agents are present in the SObjectizer Environment but they can't handle any events (even so_evt_start is not called). It is possible to send a message to a frozen agent, but this message will wait in some event queue while the agent will be unfrozen.
All agents those are registered before a call to run_for will be automatically unfrozen when run_for is called. It means that so_evt_start for Pinger agent will be called only when we call run_for in our scenario.
Thanks for your quick reply. I've added some test scenario steps and the problem is gone in this simplified test case. In my original test code I had several test steps but it seems like that was a problem with some of these steps and as a result the mentioned exception occurred. Thanks for the solution and explanations!
Hello, I am using sobjectizer in my work project and trying to write some tests for a simple agent using
testing_env_t
testing environment. I already tested another agent without issues but when I try to test an agent that creates child cooperations I got an error.Some environment info:
sobjectizer 5.7.2
installed from conangcc 11
Simple test agent:
Test code looks like this:
When I run this test I get an exception from sobjectizer:
When I remove
so_5::introduce_child_coop
fromTestAgent::so_evt_start
then all is ok.Am I doing something wrong? How could I test an agent with a child cooperation created inside it?