Skip to content

Commit dd91170

Browse files
Update expectations of tests to remain compatible with non-DDS middlewares (#248) (#251)
Signed-off-by: Yadunund <yadunund@gmail.com> (cherry picked from commit 6c81f54) Co-authored-by: yadunund <yadunund@gmail.com>
1 parent b24f1a7 commit dd91170

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

test_rmw_implementation/test/test_publisher.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ TEST_F(TestPublisherUse, count_mismatched_subscriptions) {
398398
rmw_create_subscription(node, ts, topic_name, &other_qos_profile, &options);
399399
ASSERT_NE(nullptr, sub) << rmw_get_error_string().str;
400400

401+
// For DDS-based middlewares, the QoS defined above might result in a mismatch while it might not
402+
// for other middlewares. Hence, we rely on rmw_qos_profile_check_compatible to infer whether
403+
// the publisher and subscription will match and accordingly evaluate match counts.
404+
rmw_qos_compatibility_type_t compat;
405+
rmw_ret_t rmw_ret =
406+
rmw_qos_profile_check_compatible(qos_profile, other_qos_profile, &compat, nullptr, 0);
407+
ASSERT_EQ(rmw_ret, RMW_RET_OK);
408+
401409
// TODO(hidmic): revisit when https://github.com/ros2/rmw/issues/264 is resolved.
402410
SLEEP_AND_RETRY_UNTIL(rmw_intraprocess_discovery_delay, rmw_intraprocess_discovery_delay * 10) {
403411
ret = rmw_publisher_count_matched_subscriptions(pub, &subscription_count);
@@ -410,7 +418,11 @@ TEST_F(TestPublisherUse, count_mismatched_subscriptions) {
410418
ret = rmw_publisher_count_matched_subscriptions(pub, &subscription_count);
411419
});
412420
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
413-
EXPECT_EQ(0u, subscription_count);
421+
if (compat == RMW_QOS_COMPATIBILITY_OK) {
422+
EXPECT_EQ(1u, subscription_count);
423+
} else {
424+
EXPECT_EQ(0u, subscription_count);
425+
}
414426

415427
ret = rmw_destroy_subscription(node, sub);
416428
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;

test_rmw_implementation/test/test_subscription.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ TEST_F(TestSubscriptionUse, count_mismatched_subscriptions) {
408408
rmw_create_publisher(node, ts, topic_name, &other_qos_profile, &options);
409409
ASSERT_NE(nullptr, pub) << rmw_get_error_string().str;
410410

411+
// For DDS-based middlewares, the QoS defined above might result in a mismatch while it might not
412+
// for other middlewares. Hence, we rely on rmw_qos_profile_check_compatible to infer whether
413+
// the publisher and subscription will match and accordingly evaluate match counts.
414+
rmw_qos_compatibility_type_t compat;
415+
rmw_ret_t rmw_ret =
416+
rmw_qos_profile_check_compatible(qos_profile, other_qos_profile, &compat, nullptr, 0);
417+
ASSERT_EQ(rmw_ret, RMW_RET_OK);
418+
411419
// TODO(hidmic): revisit when https://github.com/ros2/rmw/issues/264 is resolved.
412420
SLEEP_AND_RETRY_UNTIL(rmw_intraprocess_discovery_delay, rmw_intraprocess_discovery_delay * 10) {
413421
ret = rmw_subscription_count_matched_publishers(sub, &publisher_count);
@@ -421,7 +429,11 @@ TEST_F(TestSubscriptionUse, count_mismatched_subscriptions) {
421429
ret = rmw_subscription_count_matched_publishers(sub, &publisher_count);
422430
});
423431
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
424-
EXPECT_EQ(0u, publisher_count);
432+
if (compat == RMW_QOS_COMPATIBILITY_OK) {
433+
EXPECT_EQ(1u, publisher_count);
434+
} else {
435+
EXPECT_EQ(0u, publisher_count);
436+
}
425437

426438
ret = rmw_destroy_publisher(node, pub);
427439
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;

test_rmw_implementation/test/test_wait_set.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ class TestWaitSetUse : public TestWaitSet
117117
ASSERT_NE(nullptr, srv) << rmw_get_error_string().str;
118118
client = rmw_create_client(node, service_ts, service_name, &rmw_qos_profile_default);
119119
ASSERT_NE(nullptr, client) << rmw_get_error_string().str;
120-
rmw_ret_t ret = rmw_subscription_event_init(&event, sub, RMW_EVENT_LIVELINESS_CHANGED);
120+
rmw_ret_t ret = RMW_RET_OK;
121+
// rmw_zenoh does not support RMW_EVENT_LIVELINESS_CHANGED.
122+
// TODO(Yadunund): Rely on API suggested in https://github.com/ros2/rmw/issues/394 instead.
123+
if (std::string(rmw_get_implementation_identifier()).find("rmw_zenoh_cpp") == 0) {
124+
ret = rmw_subscription_event_init(&event, sub, RMW_EVENT_PUBLICATION_MATCHED);
125+
} else {
126+
ret = rmw_subscription_event_init(&event, sub, RMW_EVENT_LIVELINESS_CHANGED);
127+
}
121128
ASSERT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
122129
}
123130

0 commit comments

Comments
 (0)