Skip to content

Commit

Permalink
Refs #20180: Apply test suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Jesus Perez <jesusperez@eprosima.com>
  • Loading branch information
jepemi authored and cferreiragonz committed Feb 13, 2024
1 parent a4090bd commit e2d6fe3
Showing 1 changed file with 10 additions and 121 deletions.
131 changes: 10 additions & 121 deletions test/blackbox/common/BlackboxTestsTransportTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,21 +733,20 @@ TEST_P(TransportTCP, TCPv6_autofill_port)
EXPECT_TRUE(IPLocator::getPhysicalPort(p2_locators.begin()[0]) == port);
}

// Test TCPv4 transport on LARGE_DATA topology
TEST_P(TransportTCP, TCPv4_large_data_topology)
// Test TCP transport on LARGE_DATA topology
TEST_P(TransportTCP, large_data_topology)
{
eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Warning);

// Limited to 12 readers and 12 writers so as not to exceed the system's file descriptor limit.
uint16_t n_participants = 12;
constexpr uint32_t samples_per_participant = 10;
bool use_v6 = false;

/* Test configuration */
std::vector<std::unique_ptr<PubSubReader<KeyedHelloWorldPubSubType>>> readers;
std::vector<std::unique_ptr<PubSubWriter<KeyedHelloWorldPubSubType>>> writers;

for (int i = 0; i < n_participants; i++)
for (uint16_t i = 0; i < n_participants; i++)
{
readers.emplace_back(new PubSubReader<KeyedHelloWorldPubSubType>(TEST_TOPIC_NAME));
writers.emplace_back(new PubSubWriter<KeyedHelloWorldPubSubType>(TEST_TOPIC_NAME));
Expand All @@ -763,7 +762,7 @@ TEST_P(TransportTCP, TCPv4_large_data_topology)
std::shuffle(ports.begin(), ports.end(), rng);

// Reliable Keep_all to wait for all acked as end condition
for (int i = 0; i < n_participants; i++)
for (uint16_t i = 0; i < n_participants; i++)
{
writers[i]->reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS)
.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS)
Expand All @@ -780,12 +779,12 @@ TEST_P(TransportTCP, TCPv4_large_data_topology)
.resource_limits_max_samples_per_instance(samples_per_participant);

// Force TCP EDP discovery & data communication and UDP PDP discovery (NO SHM)
writers[i]->setup_large_data_tcp(use_v6, ports[i]);
readers[i]->setup_large_data_tcp(use_v6, ports[n_participants + i]);
writers[i]->setup_large_data_tcp(use_ipv6, ports[i]);
readers[i]->setup_large_data_tcp(use_ipv6, ports[n_participants + i]);
}

// Init participants
for (int i = 0; i < n_participants; i++)
for (uint16_t i = 0; i < n_participants; i++)
{
writers[i]->init();
readers[i]->init();
Expand All @@ -794,7 +793,7 @@ TEST_P(TransportTCP, TCPv4_large_data_topology)
}

// Wait for discovery
for (int i = 0; i < n_participants; i++)
for (uint16_t i = 0; i < n_participants; i++)
{
writers[i]->wait_discovery(n_participants, std::chrono::seconds(0));
ASSERT_EQ(writers[i]->get_matched(), n_participants);
Expand All @@ -819,122 +818,12 @@ TEST_P(TransportTCP, TCPv4_large_data_topology)
}
};

for (int i = 0; i < n_participants; i++)
for (uint16_t i = 0; i < n_participants; i++)
{
auto start = std::next(data.begin(), i * samples_per_participant );
auto end = std::next(start, samples_per_participant);
auto writer_data(std::list<KeyedHelloWorld>(start, end));
validate_key(writer_data, (uint16_t)i);
writers[i]->send(writer_data);
EXPECT_TRUE(writer_data.empty());
}

for (auto& reader : readers)
{
reader->block_for_all();
}
for (auto& writer : writers)
{
EXPECT_TRUE(writer->waitForAllAcked(std::chrono::seconds(5)));
}

// Destroy participants
readers.clear();
writers.clear();
}

// Test TCPv6 transport on LARGE_DATA topology
TEST_P(TransportTCP, TCPv6_large_data_topology)
{
eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Warning);

// Limited to 12 readers and 12 writers so as not to exceed the system's file descriptor limit.
uint16_t n_participants = 12;
constexpr uint32_t samples_per_participant = 10;
bool use_v6 = true;

/* Test configuration */
std::vector<std::unique_ptr<PubSubReader<KeyedHelloWorldPubSubType>>> readers;
std::vector<std::unique_ptr<PubSubWriter<KeyedHelloWorldPubSubType>>> writers;

for (int i = 0; i < n_participants; i++)
{
readers.emplace_back(new PubSubReader<KeyedHelloWorldPubSubType>(TEST_TOPIC_NAME));
writers.emplace_back(new PubSubWriter<KeyedHelloWorldPubSubType>(TEST_TOPIC_NAME));
}

// Create a vector of ports and shuffle it
std::vector<uint16_t> ports;
for (uint16_t i = 0; i < 2 * n_participants; i++)
{
ports.push_back(7200 + i);
}
auto rng = std::default_random_engine{};
std::shuffle(ports.begin(), ports.end(), rng);

// Reliable Keep_all to wait for all acked as end condition
for (int i = 0; i < n_participants; i++)
{
writers[i]->reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS)
.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS)
.durability_kind(eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS)
.lease_duration(eprosima::fastrtps::c_TimeInfinite, eprosima::fastrtps::Duration_t(3, 0))
.resource_limits_max_instances(1)
.resource_limits_max_samples_per_instance(samples_per_participant);

readers[i]->reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS)
.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS)
.durability_kind(eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS)
.lease_duration(eprosima::fastrtps::c_TimeInfinite, eprosima::fastrtps::Duration_t(3, 0))
.resource_limits_max_instances(n_participants)
.resource_limits_max_samples_per_instance(samples_per_participant);

// Force TCP EDP discovery & data communication and UDP PDP discovery (NO SHM)
writers[i]->setup_large_data_tcp(use_v6, ports[i]);
readers[i]->setup_large_data_tcp(use_v6, ports[n_participants + i]);
}

// Init participants
for (int i = 0; i < n_participants; i++)
{
writers[i]->init();
readers[i]->init();
ASSERT_TRUE(writers[i]->isInitialized());
ASSERT_TRUE(readers[i]->isInitialized());
}

// Wait for discovery
for (int i = 0; i < n_participants; i++)
{
writers[i]->wait_discovery(n_participants, std::chrono::seconds(0));
ASSERT_EQ(writers[i]->get_matched(), n_participants);
readers[i]->wait_discovery(std::chrono::seconds(0), n_participants);
ASSERT_EQ(readers[i]->get_matched(), n_participants);
}

// Send and receive data
std::list<KeyedHelloWorld> data;
data = default_keyedhelloworld_per_participant_data_generator(n_participants, samples_per_participant);

for (auto& reader : readers)
{
reader->startReception(data);
}

auto validate_key = [](const std::list<KeyedHelloWorld>& data, uint16_t participant_key)
{
for (const auto& sample : data)
{
ASSERT_EQ(sample.key(), participant_key);
}
};

for (int i = 0; i < n_participants; i++)
{
auto start = std::next(data.begin(), i * samples_per_participant );
auto end = std::next(start, samples_per_participant);
auto writer_data(std::list<KeyedHelloWorld>(start, end));
validate_key(writer_data, (uint16_t)i);
validate_key(writer_data, i);
writers[i]->send(writer_data);
EXPECT_TRUE(writer_data.empty());
}
Expand Down

0 comments on commit e2d6fe3

Please sign in to comment.