From 41343ba06e0591695ee279bd162b1f91ffe07d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Dom=C3=ADnguez=20L=C3=B3pez?= <116071334+Mario-DL@users.noreply.github.com> Date: Wed, 3 Jul 2024 07:27:33 +0200 Subject: [PATCH] Fix Latency test destruction (#5017) Signed-off-by: Mario Dominguez (cherry picked from commit d559f71c674975f3df411b591ac6f300d86b30d5) --- .../latency/LatencyTestPublisher.cpp | 49 ++++++++++--------- .../latency/LatencyTestPublisher.hpp | 2 + .../latency/LatencyTestSubscriber.cpp | 49 ++++++++++--------- .../latency/LatencyTestSubscriber.hpp | 2 + test/performance/latency/main_LatencyTest.cpp | 9 ++++ 5 files changed, 65 insertions(+), 46 deletions(-) diff --git a/test/performance/latency/LatencyTestPublisher.cpp b/test/performance/latency/LatencyTestPublisher.cpp index 60081566de7..93d002c270f 100644 --- a/test/performance/latency/LatencyTestPublisher.cpp +++ b/test/performance/latency/LatencyTestPublisher.cpp @@ -54,29 +54,6 @@ LatencyTestPublisher::LatencyTestPublisher() LatencyTestPublisher::~LatencyTestPublisher() { - // Static type endpoints shpuld have been removed for each payload iteration - if (dynamic_types_) - { - destroy_data_endpoints(); - } - else if (nullptr != data_writer_ - || nullptr != data_reader_ - || nullptr != latency_data_pub_topic_ - || nullptr != latency_data_sub_topic_ - || !latency_data_type_) - { - EPROSIMA_LOG_ERROR(LATENCYPUBLISHER, "ERROR unregistering the DATA type and/or removing the endpoints"); - } - - subscriber_->delete_datareader(command_reader_); - participant_->delete_subscriber(subscriber_); - - publisher_->delete_datawriter(command_writer_); - participant_->delete_publisher(publisher_); - - participant_->delete_topic(latency_command_sub_topic_); - participant_->delete_topic(latency_command_pub_topic_); - std::string TestCommandType("TestCommandType"); participant_->unregister_type(TestCommandType); @@ -675,6 +652,32 @@ void LatencyTestPublisher::run() } } +void LatencyTestPublisher::destroy_user_entities() +{ + // Static type endpoints shpuld have been removed for each payload iteration + if (dynamic_types_) + { + destroy_data_endpoints(); + } + else if (nullptr != data_writer_ + || nullptr != data_reader_ + || nullptr != latency_data_pub_topic_ + || nullptr != latency_data_sub_topic_ + || !latency_data_type_) + { + EPROSIMA_LOG_ERROR(LATENCYPUBLISHER, "ERROR unregistering the DATA type and/or removing the endpoints"); + } + + subscriber_->delete_datareader(command_reader_); + participant_->delete_subscriber(subscriber_); + + publisher_->delete_datawriter(command_writer_); + participant_->delete_publisher(publisher_); + + participant_->delete_topic(latency_command_sub_topic_); + participant_->delete_topic(latency_command_pub_topic_); +} + void LatencyTestPublisher::export_csv( const std::string& data_name, const std::string& str_reliable, diff --git a/test/performance/latency/LatencyTestPublisher.hpp b/test/performance/latency/LatencyTestPublisher.hpp index 9d68cac2ee0..9e479f3bc51 100644 --- a/test/performance/latency/LatencyTestPublisher.hpp +++ b/test/performance/latency/LatencyTestPublisher.hpp @@ -107,6 +107,8 @@ class LatencyTestPublisher void run(); + void destroy_user_entities(); + private: bool init_dynamic_types(); diff --git a/test/performance/latency/LatencyTestSubscriber.cpp b/test/performance/latency/LatencyTestSubscriber.cpp index 862e741e5aa..f5a6f1b9b54 100644 --- a/test/performance/latency/LatencyTestSubscriber.cpp +++ b/test/performance/latency/LatencyTestSubscriber.cpp @@ -46,29 +46,6 @@ LatencyTestSubscriber::LatencyTestSubscriber() LatencyTestSubscriber::~LatencyTestSubscriber() { - // Static type endpoints should have been remove for each payload iteration - if (dynamic_types_) - { - destroy_data_endpoints(); - } - else if (nullptr != data_writer_ - || nullptr != data_reader_ - || nullptr != latency_data_pub_topic_ - || nullptr != latency_data_sub_topic_ - || !latency_data_type_) - { - EPROSIMA_LOG_ERROR(LATENCYSUBSCRIBER, "ERROR unregistering the DATA type and/or removing the endpoints"); - } - - subscriber_->delete_datareader(command_reader_); - participant_->delete_subscriber(subscriber_); - - publisher_->delete_datawriter(command_writer_); - participant_->delete_publisher(publisher_); - - participant_->delete_topic(latency_command_sub_topic_); - participant_->delete_topic(latency_command_pub_topic_); - std::string TestCommandType("TestCommandType"); participant_->unregister_type(TestCommandType); @@ -633,6 +610,32 @@ void LatencyTestSubscriber::run() } } +void LatencyTestSubscriber::destroy_user_entities() +{ + // Static type endpoints should have been remove for each payload iteration + if (dynamic_types_) + { + destroy_data_endpoints(); + } + else if (nullptr != data_writer_ + || nullptr != data_reader_ + || nullptr != latency_data_pub_topic_ + || nullptr != latency_data_sub_topic_ + || !latency_data_type_) + { + EPROSIMA_LOG_ERROR(LATENCYSUBSCRIBER, "ERROR unregistering the DATA type and/or removing the endpoints"); + } + + subscriber_->delete_datareader(command_reader_); + participant_->delete_subscriber(subscriber_); + + publisher_->delete_datawriter(command_writer_); + participant_->delete_publisher(publisher_); + + participant_->delete_topic(latency_command_sub_topic_); + participant_->delete_topic(latency_command_pub_topic_); +} + bool LatencyTestSubscriber::test( uint32_t datasize) { diff --git a/test/performance/latency/LatencyTestSubscriber.hpp b/test/performance/latency/LatencyTestSubscriber.hpp index 958f7e94cbc..f3d91baacd0 100644 --- a/test/performance/latency/LatencyTestSubscriber.hpp +++ b/test/performance/latency/LatencyTestSubscriber.hpp @@ -68,6 +68,8 @@ class LatencyTestSubscriber void run(); + void destroy_user_entities(); + bool test( uint32_t datasize); diff --git a/test/performance/latency/main_LatencyTest.cpp b/test/performance/latency/main_LatencyTest.cpp index a7131c491c9..ee4a5ee8066 100644 --- a/test/performance/latency/main_LatencyTest.cpp +++ b/test/performance/latency/main_LatencyTest.cpp @@ -504,6 +504,7 @@ int main( dynamic_types, data_sharing, data_loans, shared_memory, forced_domain, data_sizes)) { latency_publisher.run(); + latency_publisher.destroy_user_entities(); } else { @@ -519,6 +520,7 @@ int main( xml_config_file, dynamic_types, data_sharing, data_loans, shared_memory, forced_domain, data_sizes)) { latency_subscriber.run(); + latency_subscriber.destroy_user_entities(); } else { @@ -569,6 +571,13 @@ int main( { sub.join(); } + + for (auto& sub : latency_subscribers) + { + sub->destroy_user_entities(); + } + + latency_publisher.destroy_user_entities(); } else {