[rostest]Subscriber callback not being called even with getNumPublishers() > 1
So I've the following class for using Fixture tests from gtest:
class DiagnosticsMsgParserTest : public ::testing::Test {
public:
DiagnosticsMsgParserTest() {
diagnostic_sub_ = nh_.subscribe("diagnostics_agg", 100, &DiagnosticsMsgParserTest::diagnosticCB, this);
}
void SetUp() override {
while (diagnostic_pub_.getNumPublishers() < 1 && ros::ok()) {
ros::Duration(0.5).sleep();
}
ASSERT_TRUE(ros::ok());
ASSERT_EQ(1, diagnostic_pub_.getNumPublishers());
ros::spinOnce();
};
void TearDown() override {};
void diagnosticCB(const diagnostic_msgs::DiagnosticArrayConstPtr& msg) {
msg_ = *msg;
EXPECT_GT(0, 1); // just for debuggin, if callback is called this line will advertise
// some error
}
ros::NodeHandle nh_;
diagnostic_msgs::DiagnosticArray msg_;
ros::Subscriber diagnostic_sub_;
};
And the following testsuite:
TEST_F(DiagnosticsMsgParserTest, getParsedObject) {
ros::spinOnce();
const auto& parsed_objects = diagnostics_tools::DiagnosticsMsgsParser::parse(msg_);
ASSERT_EQ(1, diagnostic_sub_.getNumPublishers());
EXPECT_TRUE(ros::ok());
EXPECT_EQ(2, msg_.status.size());
ros::master::V_TopicInfo master_topics;
ros::master::getTopics(master_topics);
EXPECT_EQ(2, master_topics.size());
EXPECT_EQ("foo", master_topics[3].name);
}
Well, diagnosticCB is never called, even when diagnostic_pub_.getNumPublishers() > 1 and ros::ok() (I've an aggregator_node included from the rostest file). You can see on bellow my test-results for this suite:
<testsuite name="DiagnosticsMsgParserTest" tests="1" failures="1" disabled="0" errors="0" time="0.68">
<testcase name="getParsedObject" status="run" time="0.68" classname="DiagnosticsMsgParserTest">
<failure message="/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:49
Value of: msg_.status.size()
 Actual: 0
Expected: 2" type=""><![CDATA[/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:49
Value of: msg_.status.size()
Actual: 0
Expected: 2]]></failure>
<failure message="/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:69
Value of: master_topics.size()
 Actual: 3
Expected: 2" type=""><![CDATA[/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:69
Value of: master_topics.size()
Actual: 3
Expected: 2]]></failure>
<failure message="/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:70
Value of: master_topics[1].name
 Actual: "/diagnostics_agg"
Expected: "sad"" type=""><![CDATA[/home/caioaamaral/Workspace/mccr_ws/src/elmo_gold_ros_pkgs/elmo_gold_diagnostics/test/test_diagnostics_msg_parser.cpp:70
Value of: master_topics[1].name
Actual: "/diagnostics_agg"
Expected: "foo"]]></failure>
</testcase>
</testsuite>
It shows me that diagnostic_msgs::DiagnosticArray msg_ is never been filled by callback call, as it's empty and it didn't throw any error for EXPECT_GT(0, 1). Also, it shows that diagnostic_sub_ topic has at least one publisher advertised to it, and from strong textros::master::getTopics it shows that (by master_topics.size()) it has 3 topics being published at all, and one of then is indeed the "/diagnostics_agg".
There is no /diagnostics topic being advertised, but even there I was expecting to catch all "Stale" msgs from "/diagnostics_agg"
Does anyone have have some idea on how to make callback be called at all?