@@ -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 ;
0 commit comments