Do rostest test nodes publish to rosout?
Hello all,
Some background. I am new to writing unit tests in gtests/rostest. So a lot of this might be just me unable to find that awesome link which will clear everything up. Anyway, here it goes:
My node under test: This node is only subscribing to /rosout_agg
. Think of this as some sort of diagnostics node.
My test scenario: I want to publish several series of messages to /rosout
from my test cases and see how my diagnostics node responds to this. So I was thinking I will just use the log statements such as ROS_INFO
, ROS_WARN
and ROS_ERROR
to publish my test case messages onto /rosout
. I am not directly publishing to this topic. Rather just using the log statements.
My rostest
file looks like follows:
<?xml version="1.0"?>
<launch>
<node pkg="diagnostics" type="diagnostics" name="diagnostics_node" output="screen"/>
<test test-name="diagnostics_test_node" pkg="diagnostics" type="diagnostics_test_node"/>
</launch>
- When I run this file using
rostest
, my diagnostics node is not picking up any messages from/rosout_agg
. The subscriber callback in my node under test never gets called. - Note that, when I run my
diagnostics_test_node
as just a gtest and my diagnostics node separately, everything is working as expected.
So the question I have is, do the test nodes that rostest
starts automatically start a rosout
as well (The XML file does not seem to have any mention of rosout)? What happens to the messages created by the log statements in the test node in this case? Should I be directly publishing to /rosout
instead of using log statements? Any other ideas on how I should be testing a stream of messages from /rosout_agg
?
Please let me know if I can expand on my question!
Asked by swaroophs on 2020-04-22 04:53:45 UTC
Answers
After further research it DOES look like rostest
nodes DO NOT automatically publish to /rosout
and hence /rosout_agg
. So if you are working with these topics, have your test nodes manually create a publisher to these topics and publish periodically so that your nodes under test can read from that.
P.S: Since I did not get an "official" answer, I'll post this one as an answer until someone else decides to enlighten us!
Asked by swaroophs on 2020-05-05 03:44:08 UTC
Comments
Update: I found a workaround. Simply launch your own rosout
node in your .test
file, with a different name, and it works just like roslaunch
:
<node name="my_rosout" pkg="rosout" type="rosout" />
This is only a half-answer, which I've figured out while debugging a similar problem.
Yes, test nodes do publish to rosout
, however, the rosout
node that subscribes to these messages and publishes rosout_agg
is not started by rostest
.
Running my test via rostest
creates a ~/.ros/log/rostest-computer-PID.log
file that does say, [roslaunch][INFO] 2020-06-01 10:51:35,758: Added core node of type [rosout/rosout] in namespace [/]
, but has no other mention of a rosout
node. By comparison, when running roslaunch
the resulting log in ~/.ros/log/latest/roslaunch-computer-PID.log
has this line, but also has a lot more about actually starting the node and publishing rosout_agg
.
To verify my theory, I also just had my node subscribe directly to rosout
instead of rosout_agg
, and it did get messages and work properly.
Asked by JohnStechschulte on 2020-06-01 12:30:27 UTC
Comments
IIRC the log level of a test is set to warn, so ros info and ros debug messages will not get written to rosout
Asked by Link on 2020-04-22 08:58:38 UTC
Thanks for the comment! Yes info and debug wont be shown unless a test node logger level is set otherwise. But I’m not seeing warns and errors be caught even though I see all my test messages on screen. In other words warn and error are seen on screen but there is no way to check if rosout is picking them.
Asked by swaroophs on 2020-04-22 09:03:32 UTC