@@ -160,7 +160,8 @@ class DDSContentFilter : public testing::TestWithParam<communication_type>
160160 {
161161 case communication_type::INTRAPROCESS:
162162 library_settings.intraprocess_delivery = eprosima::fastdds::IntraprocessDeliveryType::INTRAPROCESS_FULL;
163- eprosima::fastdds::dds::DomainParticipantFactory::get_instance ()->set_library_settings (library_settings);
163+ eprosima::fastdds::dds::DomainParticipantFactory::get_instance ()->set_library_settings (
164+ library_settings);
164165 break ;
165166 case communication_type::DATASHARING:
166167 enable_datasharing = true ;
@@ -182,7 +183,8 @@ class DDSContentFilter : public testing::TestWithParam<communication_type>
182183 {
183184 case communication_type::INTRAPROCESS:
184185 library_settings.intraprocess_delivery = eprosima::fastdds::IntraprocessDeliveryType::INTRAPROCESS_OFF;
185- eprosima::fastdds::dds::DomainParticipantFactory::get_instance ()->set_library_settings (library_settings);
186+ eprosima::fastdds::dds::DomainParticipantFactory::get_instance ()->set_library_settings (
187+ library_settings);
186188 break ;
187189 case communication_type::DATASHARING:
188190 break ;
@@ -784,7 +786,7 @@ TEST_P(DDSContentFilter, CorrectGAPSendingTwoReader)
784786 {
785787 total_count_2 = status.total_count ;
786788 }).init ();
787- ASSERT_TRUE (reader .isInitialized ());
789+ ASSERT_TRUE (reader_2 .isInitialized ());
788790
789791 // Set up the writer
790792 PubSubWriter<HelloWorldPubSubType> writer (TEST_TOPIC_NAME);
@@ -853,6 +855,97 @@ TEST(DDSContentFilter, filter_other_type_name)
853855 ASSERT_EQ (dds::DomainParticipantFactory::get_instance ()->delete_participant (participant), RETCODE_OK);
854856}
855857
858+
859+ /*
860+ * Regression test for https://eprosima.easyredmine.com/issues/24038
861+ *
862+ * This test checks that reusing a ReaderProxy object when a new DataReader is matched does not lead to incorrect
863+ * behaviour due to poorly initialised data.
864+ */
865+ TEST (DDSContentFilter, reusing_reader_proxy)
866+ {
867+ int32_t total_count {0 };
868+ int32_t total_count_2 {0 };
869+
870+ PubSubReader<HelloWorldPubSubType> reader (TEST_TOPIC_NAME, " index = 1 OR index = 2 OR index = 6" , {}, true , false ,
871+ false );
872+ reader
873+ .reliability (RELIABLE_RELIABILITY_QOS)
874+ .durability_kind (TRANSIENT_LOCAL_DURABILITY_QOS)
875+ .sample_lost_status_functor ([&total_count](const SampleLostStatus& status)
876+ {
877+ total_count = status.total_count ;
878+ }).init ();
879+ ASSERT_TRUE (reader.isInitialized ());
880+
881+ auto udp_transport = std::make_shared<UDPv4TransportDescriptor>();
882+
883+ // Set up the writer
884+ PubSubWriter<HelloWorldPubSubType> writer (TEST_TOPIC_NAME);
885+ writer
886+ .add_user_transport_to_pparams (udp_transport)
887+ .disable_builtin_transport ()
888+ .durability_kind (TRANSIENT_LOCAL_DURABILITY_QOS)
889+ .history_depth (10 )
890+ // .heartbeat_period_seconds(100)
891+ .init ();
892+ ASSERT_TRUE (writer.isInitialized ());
893+
894+ // Wait for discovery
895+ reader.wait_discovery ();
896+ writer.wait_discovery ();
897+
898+ // Send 10 samples
899+ auto data = default_helloworld_data_generator ();
900+
901+ decltype (data) expected_data;
902+ expected_data.push_back (*data.begin ()); // index 1
903+ expected_data.push_back (*std::next (data.begin ())); // index 2
904+ expected_data.push_back (*std::next (data.begin (), 5 )); // index 6
905+ decltype (data) expected_data_2;
906+ expected_data_2.push_back (*std::next (data.begin (), 8 )); // index 9
907+ expected_data_2.push_back (*std::next (data.begin (), 2 )); // index 3
908+ expected_data_2.push_back (*std::next (data.begin (), 3 )); // index 4
909+
910+ reader.startReception (expected_data);
911+
912+ writer.send (data, 50 );
913+
914+ // Wait for reception and check
915+ reader.block_for_all ();
916+ ASSERT_EQ (0 , total_count);
917+
918+ reader.destroy ();
919+
920+ data = default_helloworld_data_generator (4 );
921+
922+ writer.send (data, 50 );
923+
924+ PubSubReader<HelloWorldPubSubType> reader_2 (TEST_TOPIC_NAME, " index = 3 OR index = 4 OR index = 9" , {}, true , false ,
925+ false );
926+ reader_2
927+ .reliability (RELIABLE_RELIABILITY_QOS)
928+ .durability_kind (TRANSIENT_LOCAL_DURABILITY_QOS)
929+ .sample_lost_status_functor ([&total_count_2](const SampleLostStatus& status)
930+ {
931+ total_count_2 += status.total_count ;
932+ }).init ();
933+ ASSERT_TRUE (reader_2.isInitialized ());
934+
935+
936+ reader_2.wait_discovery ();
937+ writer.wait_discovery ();
938+
939+ data = default_helloworld_data_generator (1 );
940+
941+ writer.send (data, 50 );
942+
943+ reader_2.startReception (expected_data_2);
944+
945+ // Wait for reception and check
946+ reader_2.block_for_all ();
947+ }
948+
856949#ifdef INSTANTIATE_TEST_SUITE_P
857950#define GTEST_INSTANTIATE_TEST_MACRO (x, y, z, w ) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
858951#else
0 commit comments