From c5522a92de97b06bf0269dea767e7d48aa6c08cd Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 30 Mar 2023 11:38:20 +0200 Subject: [PATCH 1/3] Refs #17919. Added regression test. Signed-off-by: Miguel Company --- .../common/DDSBlackboxTestsDiscovery.cpp | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp b/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp index 8cc6dcf0796..d19b8f2074a 100644 --- a/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp +++ b/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp @@ -1511,3 +1511,95 @@ TEST(DDSDiscovery, CheckIncorrectWriterDurabilityQosXmlStaticDiscoveryFile) DomainParticipantFactory* factory = DomainParticipantFactory::get_instance(); ASSERT_EQ(factory->check_xml_static_discovery(file), ReturnCode_t::RETCODE_ERROR); } + +/** + * Regression test for redmine issue #17919 + */ +static void test_DDSDiscovery_WaitSetMatchedStatus( + bool with_listener) +{ + using namespace eprosima; + + auto factory = fastdds::dds::DomainParticipantFactory::get_instance(); + fastdds::dds::DomainParticipantQos pqos; + factory->get_default_participant_qos(pqos); + uint32_t ignore_flags = + fastrtps::rtps::ParticipantFilteringFlags::FILTER_DIFFERENT_HOST | + fastrtps::rtps::ParticipantFilteringFlags::FILTER_DIFFERENT_PROCESS; + pqos.wire_protocol().builtin.discovery_config.ignoreParticipantFlags = + static_cast(ignore_flags); + + fastdds::dds::DomainParticipantListener listener; + auto listener_to_use = with_listener ? &listener : nullptr; + + fastdds::dds::DomainParticipant* participant = factory->create_participant(0, pqos, listener_to_use); + ASSERT_NE(participant, nullptr); + + fastdds::dds::TypeSupport type(new HelloWorldPubSubType()); + EXPECT_EQ(type.register_type(participant), ReturnCode_t::RETCODE_OK); + + auto topic = participant->create_topic(TEST_TOPIC_NAME, type->getName(), fastdds::dds::TOPIC_QOS_DEFAULT); + ASSERT_NE(topic, nullptr); + + auto publisher = participant->create_publisher(fastdds::dds::PUBLISHER_QOS_DEFAULT); + ASSERT_NE(publisher, nullptr); + + auto data_writer = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + ASSERT_NE(data_writer, nullptr); + + auto thread_run = [data_writer]() + { + fastdds::dds::WaitSet wait_set; + fastdds::dds::ConditionSeq triggered_conditions; + + fastdds::dds::StatusCondition& condition = data_writer->get_statuscondition(); + condition.set_enabled_statuses(fastdds::dds::StatusMask::publication_matched()); + wait_set.attach_condition(condition); + + fastdds::dds::PublicationMatchedStatus matched_status{}; + while (1 > matched_status.current_count) + { + ReturnCode_t ret_code = wait_set.wait(triggered_conditions, fastrtps::c_TimeInfinite); + if (ReturnCode_t::RETCODE_OK != ret_code) + { + continue; + } + + for (fastdds::dds::Condition* cond : triggered_conditions) + { + fastdds::dds::StatusCondition* status_cond = dynamic_cast(cond); + if (nullptr != status_cond) + { + EXPECT_EQ(status_cond, &condition); + fastdds::dds::Entity* entity = status_cond->get_entity(); + EXPECT_EQ(entity, data_writer); + fastdds::dds::StatusMask changed_statuses = entity->get_status_changes(); + + if (changed_statuses.is_active(fastdds::dds::StatusMask::publication_matched())) + { + data_writer->get_publication_matched_status(matched_status); + } + } + } + } + }; + + std::thread waiting_thread(thread_run); + + auto subscriber = participant->create_subscriber(fastdds::dds::SUBSCRIBER_QOS_DEFAULT); + ASSERT_NE(subscriber, nullptr); + + auto data_reader = subscriber->create_datareader(topic, fastdds::dds::DATAREADER_QOS_DEFAULT); + ASSERT_NE(data_reader, nullptr); + + waiting_thread.join(); + + participant->delete_contained_entities(); + factory->delete_participant(participant); +} + +TEST(DDSDiscovery, WaitSetMatchedStatus) +{ + test_DDSDiscovery_WaitSetMatchedStatus(false); + test_DDSDiscovery_WaitSetMatchedStatus(true); +} From 6f01e98b479ea7e69b3ad08b0181c0994191ec8d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 30 Mar 2023 10:29:26 +0200 Subject: [PATCH 2/3] Refs #17919. Fix DataReaderImpl. Signed-off-by: Miguel Company --- src/cpp/fastdds/subscriber/DataReaderImpl.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index 0cc01c90bc0..11d36614c76 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -924,10 +924,7 @@ void DataReaderImpl::InnerDataReaderListener::onReaderMatched( listener->on_subscription_matched(data_reader_->user_datareader_, callback_status); } } - else - { - data_reader_->user_datareader_->get_statuscondition().get_impl()->set_status(notify_status, true); - } + data_reader_->user_datareader_->get_statuscondition().get_impl()->set_status(notify_status, true); } void DataReaderImpl::InnerDataReaderListener::on_liveliness_changed( From 927ab3b1059860b99126892c805b2c70768abef5 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 30 Mar 2023 10:36:44 +0200 Subject: [PATCH 3/3] Refs #17919. Fix DataWriterImpl. Signed-off-by: Miguel Company --- src/cpp/fastdds/publisher/DataWriterImpl.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cpp/fastdds/publisher/DataWriterImpl.cpp b/src/cpp/fastdds/publisher/DataWriterImpl.cpp index ee94db1b82d..e0504874778 100644 --- a/src/cpp/fastdds/publisher/DataWriterImpl.cpp +++ b/src/cpp/fastdds/publisher/DataWriterImpl.cpp @@ -1203,10 +1203,7 @@ void DataWriterImpl::InnerDataWriterListener::onWriterMatched( listener->on_publication_matched(data_writer_->user_datawriter_, callback_status); } } - else - { - data_writer_->user_datawriter_->get_statuscondition().get_impl()->set_status(notify_status, true); - } + data_writer_->user_datawriter_->get_statuscondition().get_impl()->set_status(notify_status, true); } void DataWriterImpl::InnerDataWriterListener::on_offered_incompatible_qos(