Skip to content

Commit 4f331c8

Browse files
MiguelCompanyrichiware
authored andcommitted
Added discovery regression test [5479] (#542)
* Refs #5453 Adding a test for discovery with thirty participants * Refs #5453 Updating the test to check for matched readers/writers * Refs #5453. Added test for multiple participants with multiple topics. * Refs #5479. Fixing warnings on Mac. * Refs #5479. Changed test to fail by timeout pattern. * Refs #5479. Taking removal and unmatching into account. * Refs #5479. Styling and no copy. * Refs #5479. Fixing valgrind. * Refs #5479. Avoiding possible port collisions. * Refs #5479. Removing debug print methods. * Refs #5479. Adding debug messages to persistence tests. * Refs #5479. Closing participants. * Refs #5479. Adding more info to persistence tests. * Refs #5479. Fix build errors after rebase. * Refs #4579. Addressing review comments.
1 parent 0eb30f7 commit 4f331c8

File tree

4 files changed

+403
-37
lines changed

4 files changed

+403
-37
lines changed

test/blackbox/BlackboxTestsDiscovery.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "BlackboxTests.hpp"
1616

17+
#include "PubSubWriterReader.hpp"
1718
#include "PubSubReader.hpp"
1819
#include "PubSubWriter.hpp"
1920

@@ -481,3 +482,120 @@ TEST(BlackBox, PubSubAsReliableHelloworldUserData)
481482

482483
reader.wait_discovery_result();
483484
}
485+
486+
//! Tests discovery of 20 participants, having one publisher and one subscriber each
487+
TEST(Discovery, TwentyParticipants)
488+
{
489+
// Number of participants
490+
constexpr size_t n_participants = 20;
491+
// Wait time for discovery
492+
constexpr unsigned int wait_ms = 20;
493+
494+
std::vector<std::shared_ptr<PubSubWriterReader<HelloWorldType>>> pubsub;
495+
pubsub.reserve(n_participants);
496+
497+
for (unsigned int i=0; i<n_participants; i++)
498+
{
499+
pubsub.emplace_back(std::make_shared<PubSubWriterReader<HelloWorldType>>(TEST_TOPIC_NAME));
500+
}
501+
502+
// Initialization of all the participants
503+
for (auto& ps : pubsub)
504+
{
505+
ps->init();
506+
ASSERT_EQ(ps->isInitialized(), true);
507+
}
508+
509+
bool all_discovered = false;
510+
while (!all_discovered)
511+
{
512+
all_discovered = true;
513+
514+
for (auto& ps : pubsub)
515+
{
516+
if ((ps->get_num_discovered_participants() < n_participants - 1) ||
517+
(ps->get_num_discovered_publishers() < n_participants) ||
518+
(ps->get_num_discovered_subscribers() < n_participants) ||
519+
(ps->get_publication_matched() < n_participants) ||
520+
(ps->get_subscription_matched() < n_participants))
521+
{
522+
all_discovered = false;
523+
break;
524+
}
525+
}
526+
527+
if (!all_discovered)
528+
{
529+
// Give some time so that participants can discover each other
530+
std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms));
531+
}
532+
}
533+
534+
// Test will fail by timeout if a discovery error happens
535+
std::cout << "All discovered. Closing participants..." << std::endl;
536+
for (auto& ps : pubsub)
537+
{
538+
ps->destroy();
539+
}
540+
}
541+
542+
//! Regression for ROS2 #280 and #281
543+
TEST(Discovery, TwentyParticipantsSeveralEndpoints)
544+
{
545+
// Number of participants
546+
constexpr size_t n_participants = 20;
547+
// Number of endpoints
548+
constexpr size_t n_topics = 10;
549+
// Total number of discovered endpoints
550+
constexpr size_t n_total_endpoints = n_participants * n_topics;
551+
// Wait time for discovery
552+
constexpr unsigned int wait_ms = 20;
553+
554+
std::vector<std::shared_ptr<PubSubWriterReader<HelloWorldType>>> pubsub;
555+
pubsub.reserve(n_participants);
556+
557+
for (unsigned int i = 0; i < n_participants; i++)
558+
{
559+
pubsub.emplace_back(std::make_shared<PubSubWriterReader<HelloWorldType>>(TEST_TOPIC_NAME));
560+
}
561+
562+
// Initialization of all the participants
563+
for (auto& ps : pubsub)
564+
{
565+
ps->init();
566+
ASSERT_EQ(ps->isInitialized(), true);
567+
ASSERT_TRUE(ps->create_additional_topics(n_topics - 1));
568+
}
569+
570+
bool all_discovered = false;
571+
while (!all_discovered)
572+
{
573+
all_discovered = true;
574+
575+
for (auto& ps : pubsub)
576+
{
577+
if ((ps->get_num_discovered_participants() < n_participants - 1) ||
578+
(ps->get_num_discovered_publishers() < n_total_endpoints) ||
579+
(ps->get_num_discovered_subscribers() < n_total_endpoints) ||
580+
(ps->get_publication_matched() < n_total_endpoints) ||
581+
(ps->get_subscription_matched() < n_total_endpoints))
582+
{
583+
all_discovered = false;
584+
break;
585+
}
586+
}
587+
588+
if (!all_discovered)
589+
{
590+
// Give some time so that participants can discover each other
591+
std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms));
592+
}
593+
}
594+
595+
// Test will fail by timeout if a discovery error happens
596+
std::cout << "All discovered. Closing participants..." << std::endl;
597+
for (auto& ps : pubsub)
598+
{
599+
ps->destroy();
600+
}
601+
}

test/blackbox/BlackboxTestsPersistence.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class BlackBoxPersistence : public ::testing::Test
4242
writer.wait_discovery();
4343
reader.wait_discovery();
4444

45+
std::cout << "Discovery finished." << std::endl;
46+
4547
auto data = default_helloworld_data_generator();
48+
size_t n_samples = data.size();
4649
not_received_data.insert(not_received_data.end(), data.begin(), data.end());
4750

4851
reader.expected_data(not_received_data);
@@ -56,21 +59,28 @@ class BlackBoxPersistence : public ::testing::Test
5659
// Block reader until reception finished or timeout.
5760
if (seq_check > 0)
5861
{
62+
std::cout << "Reader waiting for sequence " << seq_check << "." << std::endl;
5963
reader.block_until_seq_number_greater_or_equal({ 0,seq_check });
6064
}
6165
else
6266
{
6367
if (reliable)
6468
{
69+
std::cout << "Reader waiting for " << n_samples << " samples." << std::endl;
6570
reader.block_for_all();
6671
}
6772
else
6873
{
74+
std::cout << "Reader waiting for 2 samples." << std::endl;
6975
reader.block_for_at_least(2);
7076
}
7177
}
7278

79+
std::cout << "Last received sequence was " << reader.get_last_received_sequence_number() << std::endl;
80+
81+
std::cout << "Destroying reader..." << std::endl;
7382
reader.destroy();
83+
std::cout << "Destroying writer..." << std::endl;
7484
writer.destroy();
7585

7686
data = reader.not_received_data();

0 commit comments

Comments
 (0)