Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added discovery regression test [5479] #542

Merged
merged 15 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions test/blackbox/BlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "BlackboxTests.hpp"

#include "PubSubWriterReader.hpp"
#include "PubSubReader.hpp"
#include "PubSubWriter.hpp"

Expand Down Expand Up @@ -481,3 +482,120 @@ TEST(BlackBox, PubSubAsReliableHelloworldUserData)

reader.wait_discovery_result();
}

//! Tests discovery of 20 participants, having one publisher and one subscriber each
TEST(Discovery, TwentyParticipants)
{
// Number of participants
constexpr size_t n_participants = 20;
// Wait time for discovery
constexpr unsigned int wait_ms = 20;

std::vector<std::shared_ptr<PubSubWriterReader<HelloWorldType>>> pubsub;
pubsub.reserve(n_participants);

for (unsigned int i=0; i<n_participants; i++)
{
pubsub.emplace_back(std::make_shared<PubSubWriterReader<HelloWorldType>>(TEST_TOPIC_NAME));
}

// Initialization of all the participants
for (auto& ps : pubsub)
{
ps->init();
ASSERT_EQ(ps->isInitialized(), true);
}

bool all_discovered = false;
while (!all_discovered)
{
all_discovered = true;

for (auto& ps : pubsub)
{
if ((ps->get_num_discovered_participants() < n_participants - 1) ||
(ps->get_num_discovered_publishers() < n_participants) ||
(ps->get_num_discovered_subscribers() < n_participants) ||
(ps->get_publication_matched() < n_participants) ||
(ps->get_subscription_matched() < n_participants))
{
all_discovered = false;
break;
}
}

if (!all_discovered)
{
// Give some time so that participants can discover each other
std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms));
}
}

// Test will fail by timeout if a discovery error happens
std::cout << "All discovered. Closing participants..." << std::endl;
for (auto& ps : pubsub)
{
ps->destroy();
}
}

//! Regression for ROS2 #280 and #281
TEST(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
constexpr unsigned int wait_ms = 20;

std::vector<std::shared_ptr<PubSubWriterReader<HelloWorldType>>> pubsub;
pubsub.reserve(n_participants);

for (unsigned int i = 0; i < n_participants; i++)
{
pubsub.emplace_back(std::make_shared<PubSubWriterReader<HelloWorldType>>(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));
}

bool all_discovered = false;
while (!all_discovered)
{
all_discovered = true;

for (auto& ps : pubsub)
{
if ((ps->get_num_discovered_participants() < n_participants - 1) ||
(ps->get_num_discovered_publishers() < n_total_endpoints) ||
(ps->get_num_discovered_subscribers() < n_total_endpoints) ||
(ps->get_publication_matched() < n_total_endpoints) ||
(ps->get_subscription_matched() < n_total_endpoints))
{
all_discovered = false;
break;
}
}

if (!all_discovered)
{
// Give some time so that participants can discover each other
std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms));
}
}

// Test will fail by timeout if a discovery error happens
std::cout << "All discovered. Closing participants..." << std::endl;
for (auto& ps : pubsub)
{
ps->destroy();
}
}
10 changes: 10 additions & 0 deletions test/blackbox/BlackboxTestsPersistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class BlackBoxPersistence : public ::testing::Test
writer.wait_discovery();
reader.wait_discovery();

std::cout << "Discovery finished." << std::endl;

auto data = default_helloworld_data_generator();
size_t n_samples = data.size();
not_received_data.insert(not_received_data.end(), data.begin(), data.end());

reader.expected_data(not_received_data);
Expand All @@ -56,21 +59,28 @@ class BlackBoxPersistence : public ::testing::Test
// Block reader until reception finished or timeout.
if (seq_check > 0)
{
std::cout << "Reader waiting for sequence " << seq_check << "." << std::endl;
reader.block_until_seq_number_greater_or_equal({ 0,seq_check });
}
else
{
if (reliable)
{
std::cout << "Reader waiting for " << n_samples << " samples." << std::endl;
reader.block_for_all();
}
else
{
std::cout << "Reader waiting for 2 samples." << std::endl;
reader.block_for_at_least(2);
}
}

std::cout << "Last received sequence was " << reader.get_last_received_sequence_number() << std::endl;

std::cout << "Destroying reader..." << std::endl;
reader.destroy();
std::cout << "Destroying writer..." << std::endl;
writer.destroy();

data = reader.not_received_data();
Expand Down
Loading