From e82aa152a6cf1f9394ae106b74a224ba5eb30414 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 27 May 2019 12:25:52 +0200 Subject: [PATCH] Refs #5453. Added test for multiple participants with multiple topics. --- test/blackbox/BlackboxTestsDiscovery.cpp | 57 ++++++++++++++++++++---- test/blackbox/PubSubWriterReader.hpp | 39 +++++++++++++--- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/test/blackbox/BlackboxTestsDiscovery.cpp b/test/blackbox/BlackboxTestsDiscovery.cpp index 7bc6ef025b6..232d0f2f974 100644 --- a/test/blackbox/BlackboxTestsDiscovery.cpp +++ b/test/blackbox/BlackboxTestsDiscovery.cpp @@ -487,14 +487,14 @@ BLACKBOXTEST(BlackBox, PubSubAsReliableHelloworldUserData) BLACKBOXTEST(Discovery, TwentyParticipants) { // Number of participants - unsigned int n = 20; + constexpr size_t n_participants = 20; // Wait time for discovery unsigned int wait_ms = 1500; std::vector> pubsub; - pubsub.reserve(n); + pubsub.reserve(n_participants); - for (unsigned int i=0; i> pubsub; + pubsub.reserve(n_participants); + + for (unsigned int i = 0; i < n_participants; i++) + { + pubsub.emplace_back(TEST_TOPIC_NAME); + } + + // Initialization of all the participants + for (auto& ps : pubsub) + { + ps.init(); + ASSERT_EQ(ps.isInitialized(), true); + ASSERT_TRUE(ps.create_additional_topics(n_topics - 1)); + } + + // Give some time so that participants can discover each other + std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms)); + + for (auto& ps : pubsub) + { + EXPECT_EQ(ps.get_num_discovered_participants(), n_participants - 1); + EXPECT_EQ(ps.get_num_discovered_publishers(), n_total_endpoints); + EXPECT_EQ(ps.get_num_discovered_subscribers(), n_total_endpoints); + EXPECT_EQ(ps.get_publication_matched(), n_total_endpoints); + EXPECT_EQ(ps.get_subscription_matched(), n_total_endpoints); } } diff --git a/test/blackbox/PubSubWriterReader.hpp b/test/blackbox/PubSubWriterReader.hpp index a412d89b26f..ae35ed72426 100644 --- a/test/blackbox/PubSubWriterReader.hpp +++ b/test/blackbox/PubSubWriterReader.hpp @@ -284,6 +284,35 @@ class PubSubWriterReader } } + bool create_additional_topics(int num_topics) + { + bool ret_val = initialized_; + if (ret_val) + { + std::string topic_name = publisher_attr_.topic.topicName; + + for (int i = 0; ret_val && (i < num_topics); i++) + { + topic_name += "/"; + publisher_attr_.topic.topicName = topic_name; + ret_val &= + nullptr != eprosima::fastrtps::Domain::createPublisher(participant_, publisher_attr_, &pub_listener_); + } + + topic_name = subscriber_attr_.topic.topicName; + + for (int i = 0; ret_val && (i < num_topics); i++) + { + topic_name += "/"; + subscriber_attr_.topic.topicName = topic_name; + ret_val &= + nullptr != eprosima::fastrtps::Domain::createSubscriber(participant_, subscriber_attr_, &sub_listener_); + } + } + + return ret_val; + } + bool isInitialized() const { return initialized_; } void destroy() @@ -429,17 +458,17 @@ class PubSubWriterReader return *this; } - unsigned int get_num_discovered_participants() const + size_t get_num_discovered_participants() const { return participant_listener_.discovered_participants_.size(); } - unsigned int get_num_discovered_publishers() const + size_t get_num_discovered_publishers() const { return participant_listener_.discovered_publishers_.size(); } - unsigned int get_num_discovered_subscribers() const + size_t get_num_discovered_subscribers() const { return participant_listener_.discovered_subscribers_.size(); } @@ -509,13 +538,13 @@ class PubSubWriterReader std::cout << std::endl; } - unsigned int get_publication_matched() + size_t get_publication_matched() { std::unique_lock lock(mutexDiscovery_); return matched_writers_.size(); } - unsigned int get_subscription_matched() + size_t get_subscription_matched() { std::unique_lock lock(mutexDiscovery_); return matched_readers_.size();