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