From 4a7c79430538ba3ac3087a64b1aa09035d850290 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 12:56:58 +0200 Subject: [PATCH] Automatically unmatch remote participants on participant deletion (#4849) (#4863) * Refs #21055. Add regresion test. Signed-off-by: Miguel Company * Refs #21055. Remove `this->` on PDP.cpp Signed-off-by: Miguel Company * Refs #21055. Change nullptr comparisons on PDP.cpp Signed-off-by: Miguel Company * Refs #21055. Change nullptr comparisons on BuiltinProtocols.cpp Signed-off-by: Miguel Company * Refs #21055. Split `PDP::remove_remote_participant` in two methods. Signed-off-by: Miguel Company * Refs #21055. Call new `PDP::disable` method when deleting `BuiltinProtocols`. Signed-off-by: Miguel Company * Refs #21055. `PDP::disable` method automatically unmatches remote participants. Signed-off-by: Miguel Company * Refs #21055. Use `std::lock_guard` where possible. Signed-off-by: Miguel Company * Refs #20995. Apply suggestion. Signed-off-by: Miguel Company * Refs #20995. Fix test build. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company (cherry picked from commit 689dd3f15588764d7d2fa37f4a060c5c63ee63dd) Co-authored-by: Miguel Company --- .../rtps/builtin/discovery/participant/PDP.h | 21 ++ src/cpp/rtps/builtin/BuiltinProtocols.cpp | 25 +- .../builtin/discovery/participant/PDP.cpp | 229 ++++++++++-------- .../blackbox/common/DDSBlackboxTestsBasic.cpp | 45 ++++ 4 files changed, 209 insertions(+), 111 deletions(-) diff --git a/include/fastdds/rtps/builtin/discovery/participant/PDP.h b/include/fastdds/rtps/builtin/discovery/participant/PDP.h index a94d40a4e37..f9eb5f2731b 100644 --- a/include/fastdds/rtps/builtin/discovery/participant/PDP.h +++ b/include/fastdds/rtps/builtin/discovery/participant/PDP.h @@ -126,6 +126,11 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable */ bool enable(); + /** + * @brief Disable the Participant Discovery Protocol + */ + void disable(); + virtual bool init( RTPSParticipantImpl* part) = 0; @@ -639,6 +644,22 @@ class PDP : public fastdds::statistics::rtps::IProxyQueryable */ void set_external_participant_properties_( ParticipantProxyData* participant_data); + + /** + * Performs all the necessary actions after removing a ParticipantProxyData from the + * participant_proxies_ collection. + * + * @param pdata ParticipantProxyData that was removed. + * @param partGUID GUID of the removed participant. + * @param reason Reason why the participant was removed. + * @param listener Listener to be notified of the unmatches / removal. + */ + void actions_on_remote_participant_removed( + ParticipantProxyData* pdata, + const GUID_t& partGUID, + ParticipantDiscoveryInfo::DISCOVERY_STATUS reason, + RTPSParticipantListener* listener); + }; diff --git a/src/cpp/rtps/builtin/BuiltinProtocols.cpp b/src/cpp/rtps/builtin/BuiltinProtocols.cpp index 951d1ed2f8f..005c3aa363d 100644 --- a/src/cpp/rtps/builtin/BuiltinProtocols.cpp +++ b/src/cpp/rtps/builtin/BuiltinProtocols.cpp @@ -58,9 +58,12 @@ BuiltinProtocols::BuiltinProtocols() BuiltinProtocols::~BuiltinProtocols() { // Send participant is disposed - if (mp_PDP != nullptr) + if (nullptr != mp_PDP) { + // Send participant is disposed mp_PDP->announceParticipantState(true, true); + // Consider all discovered participants as disposed + mp_PDP->disable(); } // TODO Auto-generated destructor stub @@ -199,7 +202,7 @@ bool BuiltinProtocols::addLocalWriter( { bool ok = true; - if (mp_PDP != nullptr) + if (nullptr != mp_PDP) { ok = mp_PDP->getEDP()->newLocalWriterProxyData(w, topicAtt, wqos); @@ -214,7 +217,7 @@ bool BuiltinProtocols::addLocalWriter( EPROSIMA_LOG_WARNING(RTPS_EDP, "EDP is not used in this Participant, register a Writer is impossible"); } - if (mp_WLP != nullptr) + if (nullptr != mp_WLP) { ok &= mp_WLP->add_local_writer(w, wqos); } @@ -234,7 +237,7 @@ bool BuiltinProtocols::addLocalReader( { bool ok = true; - if (mp_PDP != nullptr) + if (nullptr != mp_PDP) { ok = mp_PDP->getEDP()->newLocalReaderProxyData(R, topicAtt, rqos, content_filter); @@ -249,7 +252,7 @@ bool BuiltinProtocols::addLocalReader( EPROSIMA_LOG_WARNING(RTPS_EDP, "EDP is not used in this Participant, register a Reader is impossible"); } - if (mp_WLP != nullptr) + if (nullptr != mp_WLP) { ok &= mp_WLP->add_local_reader(R, rqos); } @@ -263,7 +266,7 @@ bool BuiltinProtocols::updateLocalWriter( const WriterQos& wqos) { bool ok = false; - if (mp_PDP != nullptr && mp_PDP->getEDP() != nullptr) + if ((nullptr != mp_PDP) && (nullptr != mp_PDP->getEDP())) { ok = mp_PDP->getEDP()->updatedLocalWriter(W, topicAtt, wqos); } @@ -277,7 +280,7 @@ bool BuiltinProtocols::updateLocalReader( const fastdds::rtps::ContentFilterProperty* content_filter) { bool ok = false; - if (mp_PDP != nullptr && mp_PDP->getEDP() != nullptr) + if ((nullptr != mp_PDP) && (nullptr != mp_PDP->getEDP())) { ok = mp_PDP->getEDP()->updatedLocalReader(R, topicAtt, rqos, content_filter); } @@ -288,11 +291,11 @@ bool BuiltinProtocols::removeLocalWriter( RTPSWriter* W) { bool ok = false; - if (mp_WLP != nullptr) + if (nullptr != mp_WLP) { ok |= mp_WLP->remove_local_writer(W); } - if (mp_PDP != nullptr && mp_PDP->getEDP() != nullptr) + if ((nullptr != mp_PDP) && (nullptr != mp_PDP->getEDP())) { ok |= mp_PDP->getEDP()->removeLocalWriter(W); } @@ -303,11 +306,11 @@ bool BuiltinProtocols::removeLocalReader( RTPSReader* R) { bool ok = false; - if (mp_WLP != nullptr) + if (nullptr != mp_WLP) { ok |= mp_WLP->remove_local_reader(R); } - if (mp_PDP != nullptr && mp_PDP->getEDP() != nullptr) + if ((nullptr != mp_PDP) && (nullptr != mp_PDP->getEDP())) { ok |= mp_PDP->getEDP()->removeLocalReader(R); } diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp index 5bfc9177b2d..549db157b70 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp @@ -324,7 +324,7 @@ void PDP::initializeParticipantProxyData( participant_data->metatraffic_locators.unicast.clear(); if (announce_locators) { - for (const Locator_t& loc : this->mp_builtin->m_metatrafficUnicastLocatorList) + for (const Locator_t& loc : mp_builtin->m_metatrafficUnicastLocatorList) { participant_data->metatraffic_locators.add_unicast_locator(loc); } @@ -335,7 +335,7 @@ void PDP::initializeParticipantProxyData( { if (!m_discovery.avoid_builtin_multicast || participant_data->metatraffic_locators.unicast.empty()) { - for (const Locator_t& loc: this->mp_builtin->m_metatrafficMulticastLocatorList) + for (const Locator_t& loc: mp_builtin->m_metatrafficMulticastLocatorList) { participant_data->metatraffic_locators.add_multicast_locator(loc); } @@ -354,7 +354,7 @@ void PDP::initializeParticipantProxyData( if (mp_RTPSParticipant->is_secure()) { IdentityToken* identity_token = nullptr; - if (mp_RTPSParticipant->security_manager().get_identity_token(&identity_token) && identity_token != nullptr) + if (mp_RTPSParticipant->security_manager().get_identity_token(&identity_token) && (nullptr != identity_token)) { participant_data->identity_token_ = std::move(*identity_token); mp_RTPSParticipant->security_manager().return_identity_token(identity_token); @@ -362,7 +362,7 @@ void PDP::initializeParticipantProxyData( PermissionsToken* permissions_token = nullptr; if (mp_RTPSParticipant->security_manager().get_permissions_token(&permissions_token) - && permissions_token != nullptr) + && (nullptr != permissions_token)) { participant_data->permissions_token_ = std::move(*permissions_token); mp_RTPSParticipant->security_manager().return_permissions_token(permissions_token); @@ -398,11 +398,13 @@ bool PDP::initPDP( //UPDATE METATRAFFIC. update_builtin_locators(); - mp_mutex->lock(); - ParticipantProxyData* pdata = add_participant_proxy_data(mp_RTPSParticipant->getGuid(), false, nullptr); - mp_mutex->unlock(); + ParticipantProxyData* pdata = nullptr; + { + std::lock_guard guardPDP(*mp_mutex); + pdata = add_participant_proxy_data(mp_RTPSParticipant->getGuid(), false, nullptr); + } - if (pdata == nullptr) + if (nullptr == pdata) { return false; } @@ -449,6 +451,24 @@ bool PDP::enable() return builtin_endpoints_->enable_pdp_readers(mp_RTPSParticipant); } +void PDP::disable() +{ + // Extract all the participant proxies excluding first one (ourselves) + std::vector participants; + { + std::lock_guard guardPDP(*this->mp_mutex); + participants.insert(participants.end(), participant_proxies_.begin() + 1, participant_proxies_.end()); + participant_proxies_.erase(participant_proxies_.begin() + 1, participant_proxies_.end()); + } + + // Unmatch all remote participants + for (ParticipantProxyData* pdata : participants) + { + actions_on_remote_participant_removed(pdata, pdata->m_guid, + ParticipantDiscoveryInfo::DISCOVERY_STATUS::REMOVED_PARTICIPANT, nullptr); + } +} + void PDP::announceParticipantState( bool new_change, bool dispose /* = false */) @@ -473,11 +493,11 @@ void PDP::announceParticipantState( { if (m_hasChangedLocalPDP.exchange(false) || new_change) { - this->mp_mutex->lock(); + mp_mutex->lock(); ParticipantProxyData* local_participant_data = getLocalParticipantProxyData(); InstanceHandle_t key = local_participant_data->m_key; ParticipantProxyData proxy_data_copy(*local_participant_data); - this->mp_mutex->unlock(); + mp_mutex->unlock(); if (history.getHistorySize() > 0) { @@ -491,7 +511,7 @@ void PDP::announceParticipantState( }, ALIVE, key); - if (change != nullptr) + if (nullptr != change) { CDRMessage_t aux_msg(change->serializedPayload); @@ -519,11 +539,11 @@ void PDP::announceParticipantState( } else { - this->mp_mutex->lock(); + mp_mutex->lock(); ParticipantProxyData* local_participant_data = getLocalParticipantProxyData(); InstanceHandle_t key = local_participant_data->m_key; ParticipantProxyData proxy_data_copy(*local_participant_data); - this->mp_mutex->unlock(); + mp_mutex->unlock(); if (history.getHistorySize() > 0) { @@ -536,7 +556,7 @@ void PDP::announceParticipantState( }, NOT_ALIVE_DISPOSED_UNREGISTERED, key); - if (change != nullptr) + if (nullptr != change) { CDRMessage_t aux_msg(change->serializedPayload); @@ -591,7 +611,7 @@ void PDP::notify_and_maybe_ignore_new_participant( << " DefLoc:" << pdata->default_locators); RTPSParticipantListener* listener = getRTPSParticipant()->getListener(); - if (listener != nullptr) + if (listener) { { std::lock_guard cb_lock(callback_mtx_); @@ -615,7 +635,7 @@ void PDP::notify_and_maybe_ignore_new_participant( bool PDP::has_reader_proxy_data( const GUID_t& reader) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == reader.guidPrefix) @@ -631,7 +651,7 @@ bool PDP::lookupReaderProxyData( const GUID_t& reader, ReaderProxyData& rdata) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == reader.guidPrefix) @@ -650,7 +670,7 @@ bool PDP::lookupReaderProxyData( bool PDP::has_writer_proxy_data( const GUID_t& writer) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == writer.guidPrefix) @@ -666,7 +686,7 @@ bool PDP::lookupWriterProxyData( const GUID_t& writer, WriterProxyData& wdata) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == writer.guidPrefix) @@ -686,7 +706,7 @@ bool PDP::removeReaderProxyData( const GUID_t& reader_guid) { EPROSIMA_LOG_INFO(RTPS_PDP, "Removing reader proxy data " << reader_guid); - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { @@ -730,7 +750,7 @@ bool PDP::removeWriterProxyData( const GUID_t& writer_guid) { EPROSIMA_LOG_INFO(RTPS_PDP, "Removing writer proxy data " << writer_guid); - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { @@ -775,7 +795,7 @@ bool PDP::lookup_participant_name( const GUID_t& guid, string_255& name) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid == guid) @@ -791,7 +811,7 @@ bool PDP::lookup_participant_key( const GUID_t& participant_guid, InstanceHandle_t& key) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid == participant_guid) @@ -814,7 +834,7 @@ ReaderProxyData* PDP::addReaderProxyData( // notify statistics module getRTPSParticipant()->on_entity_discovery(reader_guid, ParameterPropertyList_t()); - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { @@ -913,7 +933,7 @@ WriterProxyData* PDP::addWriterProxyData( // notify statistics module getRTPSParticipant()->on_entity_discovery(writer_guid, ParameterPropertyList_t()); - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { @@ -1021,7 +1041,7 @@ bool PDP::pairing_remote_reader_with_local_writer_after_security( bool PDP::get_all_local_proxies( std::vector& guids) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); ParticipantProxyData* local_participant = getLocalParticipantProxyData(); guids.reserve(local_participant->m_writers->size() + local_participant->m_readers->size() + @@ -1051,7 +1071,7 @@ bool PDP::get_serialized_proxy( bool ret = false; bool found = false; - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); if (guid.entityId == c_EntityId_RTPSParticipant) { @@ -1154,92 +1174,107 @@ bool PDP::remove_remote_participant( EPROSIMA_LOG_INFO(RTPS_PDP, partGUID ); ParticipantProxyData* pdata = nullptr; - //Remove it from our vector or RTPSParticipantProxies: - this->mp_mutex->lock(); - for (ResourceLimitedVector::iterator pit = participant_proxies_.begin(); - pit != participant_proxies_.end(); ++pit) + //Remove it from our vector of RTPSParticipantProxies { - if ((*pit)->m_guid == partGUID) + std::lock_guard guardPDP(*mp_mutex); + for (ResourceLimitedVector::iterator pit = participant_proxies_.begin(); + pit != participant_proxies_.end(); ++pit) { - pdata = *pit; - participant_proxies_.erase(pit); - break; + if ((*pit)->m_guid == partGUID) + { + pdata = *pit; + participant_proxies_.erase(pit); + break; + } } } - this->mp_mutex->unlock(); - if (pdata != nullptr) + if (nullptr != pdata) { - if (mp_EDP != nullptr) - { - RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); + RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); + actions_on_remote_participant_removed(pdata, partGUID, reason, listener); + return true; + } + + return false; +} + +void PDP::actions_on_remote_participant_removed( + ParticipantProxyData* pdata, + const GUID_t& partGUID, + ParticipantDiscoveryInfo::DISCOVERY_STATUS reason, + RTPSParticipantListener* listener) +{ + assert(nullptr != pdata); - for (auto pit : *pdata->m_readers) + if (nullptr != mp_EDP) + { + for (auto pit : *pdata->m_readers) + { + ReaderProxyData* rit = pit.second; + GUID_t reader_guid(rit->guid()); + if (reader_guid != c_Guid_Unknown) { - ReaderProxyData* rit = pit.second; - GUID_t reader_guid(rit->guid()); - if (reader_guid != c_Guid_Unknown) - { - mp_EDP->unpairReaderProxy(partGUID, reader_guid); + mp_EDP->unpairReaderProxy(partGUID, reader_guid); - if (listener) - { - ReaderDiscoveryInfo info(std::move(*rit)); - info.status = ReaderDiscoveryInfo::REMOVED_READER; - listener->onReaderDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(info)); - } + if (listener) + { + ReaderDiscoveryInfo info(std::move(*rit)); + info.status = ReaderDiscoveryInfo::REMOVED_READER; + listener->onReaderDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(info)); } } - for (auto pit : *pdata->m_writers) + } + for (auto pit : *pdata->m_writers) + { + WriterProxyData* wit = pit.second; + GUID_t writer_guid(wit->guid()); + if (writer_guid != c_Guid_Unknown) { - WriterProxyData* wit = pit.second; - GUID_t writer_guid(wit->guid()); - if (writer_guid != c_Guid_Unknown) - { - mp_EDP->unpairWriterProxy(partGUID, writer_guid, - reason == ParticipantDiscoveryInfo::DISCOVERY_STATUS::DROPPED_PARTICIPANT); + mp_EDP->unpairWriterProxy(partGUID, writer_guid, + reason == ParticipantDiscoveryInfo::DISCOVERY_STATUS::DROPPED_PARTICIPANT); - if (listener) - { - WriterDiscoveryInfo info(std::move(*wit)); - info.status = WriterDiscoveryInfo::REMOVED_WRITER; - listener->onWriterDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(info)); - } + if (listener) + { + WriterDiscoveryInfo info(std::move(*wit)); + info.status = WriterDiscoveryInfo::REMOVED_WRITER; + listener->onWriterDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(info)); } } } + } - if (mp_builtin->mp_WLP != nullptr) - { - this->mp_builtin->mp_WLP->removeRemoteEndpoints(pdata); - } + if (nullptr != mp_builtin->mp_WLP) + { + mp_builtin->mp_WLP->removeRemoteEndpoints(pdata); + } - if (mp_builtin->tlm_ != nullptr) - { - mp_builtin->tlm_->remove_remote_endpoints(pdata); - } + if (nullptr != mp_builtin->tlm_) + { + mp_builtin->tlm_->remove_remote_endpoints(pdata); + } - this->mp_EDP->removeRemoteEndpoints(pdata); - this->removeRemoteEndpoints(pdata); + mp_EDP->removeRemoteEndpoints(pdata); + removeRemoteEndpoints(pdata); #if HAVE_SECURITY - mp_builtin->mp_participantImpl->security_manager().remove_participant(*pdata); + mp_builtin->mp_participantImpl->security_manager().remove_participant(*pdata); #endif // if HAVE_SECURITY - builtin_endpoints_->remove_from_pdp_reader_history(pdata->m_key); + builtin_endpoints_->remove_from_pdp_reader_history(pdata->m_key); - auto listener = mp_RTPSParticipant->getListener(); - if (listener != nullptr) - { - std::lock_guard lock(callback_mtx_); - ParticipantDiscoveryInfo info(*pdata); - info.status = reason; - bool should_be_ignored = false; - listener->onParticipantDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move( - info), should_be_ignored); - } + if (listener) + { + std::lock_guard lock(callback_mtx_); + ParticipantDiscoveryInfo info(*pdata); + info.status = reason; + bool should_be_ignored = false; + listener->onParticipantDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move( + info), should_be_ignored); + } - this->mp_mutex->lock(); + { + std::lock_guard guardPDP(*mp_mutex); // Delete from sender resource list (TCP only) LocatorList_t remote_participant_locators; @@ -1273,7 +1308,7 @@ bool PDP::remove_remote_participant( pdata->m_writers->clear(); // Cancel lease event - if (pdata->lease_duration_event != nullptr) + if (nullptr != pdata->lease_duration_event) { pdata->lease_duration_event->cancel_timer(); } @@ -1281,13 +1316,7 @@ bool PDP::remove_remote_participant( // Return proxy object to pool pdata->clear(); participant_proxies_pool_.push_back(pdata); - - this->mp_mutex->unlock(); - - return true; } - - return false; } const BuiltinAttributes& PDP::builtin_attributes() const @@ -1298,9 +1327,9 @@ const BuiltinAttributes& PDP::builtin_attributes() const void PDP::assert_remote_participant_liveliness( const GuidPrefix_t& remote_guid) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); - for (ParticipantProxyData* it : this->participant_proxies_) + for (ParticipantProxyData* it : participant_proxies_) { if (it->m_guid.guidPrefix == remote_guid) { @@ -1315,7 +1344,7 @@ void PDP::assert_remote_participant_liveliness( CDRMessage_t PDP::get_participant_proxy_data_serialized( Endianness_t endian) { - std::lock_guard guardPDP(*this->mp_mutex); + std::lock_guard guardPDP(*mp_mutex); CDRMessage_t cdr_msg(RTPSMESSAGE_DEFAULT_SIZE); cdr_msg.msg_endian = endian; @@ -1349,7 +1378,7 @@ std::list& PDP::remote_server_a void PDP::check_remote_participant_liveliness( ParticipantProxyData* remote_participant) { - std::unique_lock guard(*this->mp_mutex); + std::unique_lock guard(*mp_mutex); if (remote_participant->should_check_lease_duration) { @@ -1429,7 +1458,7 @@ void PDP::check_and_notify_type_discovery( type_name.to_string(), type_id); } - if (dyn_type != nullptr) + if (nullptr != dyn_type) { types::DynamicPubSubType type_support(dyn_type); diff --git a/test/blackbox/common/DDSBlackboxTestsBasic.cpp b/test/blackbox/common/DDSBlackboxTestsBasic.cpp index 105e8c74125..85ed04f0692 100644 --- a/test/blackbox/common/DDSBlackboxTestsBasic.cpp +++ b/test/blackbox/common/DDSBlackboxTestsBasic.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -40,8 +41,10 @@ #include #include #include +#include #include "BlackboxTests.hpp" +#include "mock/BlackboxMockConsumer.h" #include "../api/dds-pim/CustomPayloadPool.hpp" #include "../api/dds-pim/PubSubReader.hpp" #include "../api/dds-pim/PubSubWriter.hpp" @@ -56,6 +59,48 @@ namespace dds { using ReturnCode_t = eprosima::fastrtps::types::ReturnCode_t; +/** + * This is a regression test for redmine issue #21060. + * + * It checks that when intraprocess delivery is set to full, there are no warnings in the desctructor of WriterProxy + * when deleting a participant. + */ +TEST(DDSBasic, WarningOnDelete) +{ + using namespace eprosima::fastrtps; + namespace dds = eprosima::fastdds::dds; + auto factory = dds::DomainParticipantFactory::get_instance(); + + // Set intraprocess delivery to full + LibrarySettingsAttributes library_settings; + library_settings = xmlparser::XMLProfileManager::library_settings(); + auto old_library_settings = library_settings; + library_settings.intraprocess_delivery = INTRAPROCESS_FULL; + xmlparser::XMLProfileManager::library_settings(library_settings); + + // Create participants + auto participant_1 = factory->create_participant(0, dds::PARTICIPANT_QOS_DEFAULT); + auto participant_2 = factory->create_participant(0, dds::PARTICIPANT_QOS_DEFAULT); + + /* Set up log */ + BlackboxMockConsumer* helper_consumer = new BlackboxMockConsumer(); + Log::ClearConsumers(); // Remove default consumers + Log::RegisterConsumer(std::unique_ptr(helper_consumer)); // Registering a consumer transfer ownership + // Filter specific message + dds::Log::SetErrorStringFilter(std::regex(".*~WriterProxy.*")); + dds::Log::SetVerbosity(dds::Log::Warning); + + factory->delete_participant(participant_1); + factory->delete_participant(participant_2); + + dds::Log::Flush(); + EXPECT_EQ(helper_consumer->ConsumedEntries().size(), 0u); + helper_consumer->clear_entries(); + + // Restore library settings + xmlparser::XMLProfileManager::library_settings(old_library_settings); +} + /** * This test checks whether it is safe to delete not enabled DDS entities * */