Skip to content

Commit 6f85f6a

Browse files
mergify[bot]Mario-DLMiguelCompany
authored
Properly delete builtin statistics writers upon delete_contained_entities() (#4891) (#4916)
* Properly delete builtin statistics writers upon `delete_contained_entities()` (#4891) * Refs #20816: Add BB test Signed-off-by: Mario Dominguez <[email protected]> * Refs #20816: Fix Signed-off-by: Mario Dominguez <[email protected]> * Refs #20816: Apply Edu's suggestion Signed-off-by: Mario Dominguez <[email protected]> --------- Signed-off-by: Mario Dominguez <[email protected]> (cherry picked from commit 0d62335) # Conflicts: # src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp * Fix conflicts. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> Co-authored-by: Mario Domínguez López <[email protected]> Co-authored-by: Miguel Company <[email protected]>
1 parent 8f4b4a5 commit 6f85f6a

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,8 @@ void DomainParticipantImpl::disable()
272272

273273
ReturnCode_t DomainParticipantImpl::delete_contained_entities()
274274
{
275-
ReturnCode_t ret = efd::DomainParticipantImpl::delete_contained_entities();
276-
277-
if (ret == ReturnCode_t::RETCODE_OK)
278-
{
279-
builtin_publisher_impl_ = nullptr;
280-
builtin_publisher_ = nullptr;
281-
}
282-
283-
return ret;
275+
delete_statistics_builtin_entities();
276+
return efd::DomainParticipantImpl::delete_contained_entities();
284277
}
285278

286279
efd::PublisherImpl* DomainParticipantImpl::create_publisher_impl(

src/cpp/statistics/fastdds/domain/DomainParticipantImpl.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class DomainParticipantImpl : public efd::DomainParticipantImpl
119119
* @brief This override calls the parent method and returns builtin publishers to nullptr
120120
*
121121
* @return RETCODE_OK if successful
122+
* @note This method is meant to be used followed by a deletion of the participant as it implies
123+
* the deletion of the builtin statistics publishers.
122124
*/
123125
ReturnCode_t delete_contained_entities() override;
124126

test/blackbox/common/DDSBlackboxTestsStatistics.cpp

+94
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,97 @@ TEST(DDSStatistics, discovery_topic_physical_data_delete_physical_properties)
686686
test_discovery_topic_physical_data(DiscoveryTopicPhysicalDataTest::NO_PHYSICAL_DATA);
687687
#endif // FASTDDS_STATISTICS
688688
}
689+
690+
class CustomStatisticsParticipantSubscriber : public PubSubReader<HelloWorldPubSubType>
691+
{
692+
public:
693+
694+
CustomStatisticsParticipantSubscriber(
695+
const std::string& topic_name)
696+
: PubSubReader<HelloWorldPubSubType>(topic_name)
697+
{
698+
}
699+
700+
void destroy() override
701+
{
702+
participant_->delete_contained_entities();
703+
DomainParticipantFactory::get_instance()->delete_participant(participant_);
704+
participant_ = nullptr;
705+
}
706+
707+
};
708+
709+
// Regression test for #20816. When an application is terminated with delete_contained_entities()
710+
// it has to properly finish. The test creates a number of participants with some of them sharing the same topic.
711+
// Each participant asynchronously sends and receive a number of samples. In the readers, when a minumm number of samples
712+
// is received the destroy() method is called (abruptly). The test checks that the application finishes successfully
713+
TEST(DDSStatistics, correct_deletion_upon_delete_contained_entities)
714+
{
715+
#ifdef FASTDDS_STATISTICS
716+
717+
//! Set environment variable and create participant using Qos set by code
718+
const char* value = "HISTORY_LATENCY_TOPIC;NETWORK_LATENCY_TOPIC;"
719+
"PUBLICATION_THROUGHPUT_TOPIC;SUBSCRIPTION_THROUGHPUT_TOPIC;RTPS_SENT_TOPIC;"
720+
"RTPS_LOST_TOPIC;HEARTBEAT_COUNT_TOPIC;ACKNACK_COUNT_TOPIC;NACKFRAG_COUNT_TOPIC;"
721+
"GAP_COUNT_TOPIC;DATA_COUNT_TOPIC;RESENT_DATAS_TOPIC;SAMPLE_DATAS_TOPIC;"
722+
"PDP_PACKETS_TOPIC;EDP_PACKETS_TOPIC;DISCOVERY_TOPIC;PHYSICAL_DATA_TOPIC;";
723+
724+
#ifdef _WIN32
725+
ASSERT_EQ(0, _putenv_s("FASTDDS_STATISTICS", value));
726+
#else
727+
ASSERT_EQ(0, setenv("FASTDDS_STATISTICS", value, 1));
728+
#endif // ifdef _WIN32
729+
730+
size_t n_participants = 5;
731+
size_t n_participants_same_topic = 2;
732+
733+
std::vector<std::shared_ptr<PubSubWriter<HelloWorldPubSubType>>> writers;
734+
std::vector<std::shared_ptr<CustomStatisticsParticipantSubscriber>> readers;
735+
736+
readers.reserve(n_participants);
737+
writers.reserve(n_participants);
738+
739+
std::vector<std::shared_ptr<std::thread>> threads;
740+
threads.reserve(2 * n_participants);
741+
742+
for (size_t i = 0; i < n_participants; ++i)
743+
{
744+
size_t topic_number = (i < n_participants_same_topic) ? 0 : i;
745+
746+
auto writer = std::make_shared<PubSubWriter<HelloWorldPubSubType>>(TEST_TOPIC_NAME + std::to_string(
747+
topic_number));
748+
auto reader =
749+
std::make_shared<CustomStatisticsParticipantSubscriber>(TEST_TOPIC_NAME + std::to_string(topic_number));
750+
751+
std::shared_ptr<std::list<HelloWorld>> data = std::make_shared<std::list<HelloWorld>>(default_helloworld_data_generator(
752+
10));
753+
754+
threads.emplace_back(std::make_shared<std::thread>([reader, data]()
755+
{
756+
reader->init();
757+
ASSERT_TRUE(reader->isInitialized());
758+
reader->startReception(data->size());
759+
reader->block_for_at_least(3);
760+
reader->destroy();
761+
}));
762+
763+
threads.emplace_back(std::make_shared<std::thread>([writer, data]()
764+
{
765+
writer->init();
766+
ASSERT_TRUE(writer->isInitialized());
767+
writer->wait_discovery();
768+
writer->send(*data, 10);
769+
writer->destroy();
770+
}));
771+
772+
writers.push_back(writer);
773+
readers.push_back(reader);
774+
}
775+
776+
for (auto& thread : threads)
777+
{
778+
thread->join();
779+
}
780+
781+
#endif // FASTDDS_STATISTICS
782+
}

0 commit comments

Comments
 (0)