Skip to content

Commit

Permalink
Fix regression introduced by #3396 (#3418)
Browse files Browse the repository at this point in the history
* Refs #17919. Added regression test.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #17919. Fix DataReaderImpl.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #17919. Fix DataWriterImpl.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

---------

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany authored Mar 31, 2023
1 parent d82c525 commit 7123d35
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions src/cpp/fastdds/subscriber/DataReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
92 changes: 92 additions & 0 deletions test/blackbox/common/DDSBlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fastrtps::rtps::ParticipantFilteringFlags>(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<fastdds::dds::StatusCondition*>(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);
}

0 comments on commit 7123d35

Please sign in to comment.