Skip to content

Commit

Permalink
Refs #5453. Added test for multiple participants with multiple topics.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCompany committed May 27, 2019
1 parent cc1821c commit e82aa15
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 13 deletions.
57 changes: 49 additions & 8 deletions test/blackbox/BlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PubSubWriterReader<HelloWorldType>> pubsub;
pubsub.reserve(n);
pubsub.reserve(n_participants);

for (unsigned int i=0; i<n; i++)
for (unsigned int i=0; i<n_participants; i++)
{
pubsub.emplace_back(TEST_TOPIC_NAME);
}
Expand All @@ -511,10 +511,51 @@ BLACKBOXTEST(Discovery, TwentyParticipants)

for (auto& ps : pubsub)
{
EXPECT_EQ(ps.get_num_discovered_participants(), n-1);
EXPECT_EQ(ps.get_num_discovered_publishers(), n);
EXPECT_EQ(ps.get_num_discovered_subscribers(), n);
EXPECT_EQ(ps.get_publication_matched(), n);
EXPECT_EQ(ps.get_subscription_matched(), n);
EXPECT_EQ(ps.get_num_discovered_participants(), n_participants - 1);
EXPECT_EQ(ps.get_num_discovered_publishers(), n_participants);
EXPECT_EQ(ps.get_num_discovered_subscribers(), n_participants);
EXPECT_EQ(ps.get_publication_matched(), n_participants);
EXPECT_EQ(ps.get_subscription_matched(), n_participants);
}
}

//! Regression for ROS2 #280 and #281
BLACKBOXTEST(Discovery, TwentyParticipantsSeveralEndpoints)
{
// Number of participants
constexpr size_t n_participants = 20;
// Number of endpoints
constexpr size_t n_topics = 10;
// Total number of discovered endpoints
constexpr size_t n_total_endpoints = n_participants * n_topics;
// Wait time for discovery
unsigned int wait_ms = 1500;

std::vector<PubSubWriterReader<HelloWorldType>> 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);
}
}
39 changes: 34 additions & 5 deletions test/blackbox/PubSubWriterReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -509,13 +538,13 @@ class PubSubWriterReader
std::cout << std::endl;
}

unsigned int get_publication_matched()
size_t get_publication_matched()
{
std::unique_lock<std::mutex> lock(mutexDiscovery_);
return matched_writers_.size();
}

unsigned int get_subscription_matched()
size_t get_subscription_matched()
{
std::unique_lock<std::mutex> lock(mutexDiscovery_);
return matched_readers_.size();
Expand Down

0 comments on commit e82aa15

Please sign in to comment.