I have been trying to test some code using an isolated gtest (ament_add_ros_isolated_gtest) that checks the QoS profile used to create a publisher with that reported by the NodeGraphInterface of a node using the get_publishers_info_by_topic function.

Here is an example test that demonstrates the behavior:

TEST(QoS, profile_match)
  const auto topic_name = "/test";

  const auto node = std::make_shared<rclcpp::Node>("test_node");

  rclcpp::QoS qos{rmw_qos_profile_default.depth};
  auto publisher = node->create_publisher<test_msgs::msg::BasicTypes>(topic_name, qos);

  const auto graph_event = node->get_graph_event();
  node->wait_for_graph_change(graph_event, std::chrono::milliseconds{100});

  const auto topic_endpoints = node->get_publishers_info_by_topic(topic_name);
  ASSERT_EQ(topic_endpoints.size(), std::size_t{1});

  const auto & endpoint_qos = topic_endpoints.front().qos_profile();

  EXPECT_EQ(static_cast<int>(endpoint_qos.history()), static_cast<int>(qos.history()));
  EXPECT_EQ(endpoint_qos.depth(), qos.depth());

and the output of the test:

[----------] 1 test from QoS
[ RUN      ] QoS.profile_match
.cpp:123: Failure
Expected equality of these values:
    Which is: 3
    Which is: 1
.cpp:124: Failure
Expected equality of these values:
    Which is: 0
    Which is: 10
[  FAILED  ] QoS.profile_match (4 ms)

The QoS profile reported by the get_publishers_info_by_topic has a HistoryProfile of Unknown or int value 3. I assume this is then why the depth() is returning 0.

Does anybody have an idea why there is this mismatch?

Thanks for the help!



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.