@@ -686,3 +686,97 @@ TEST(DDSStatistics, discovery_topic_physical_data_delete_physical_properties)
686
686
test_discovery_topic_physical_data (DiscoveryTopicPhysicalDataTest::NO_PHYSICAL_DATA);
687
687
#endif // FASTDDS_STATISTICS
688
688
}
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