Skip to content

Commit

Permalink
Refs #12533. Add blackbox test.
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware committed Dec 13, 2021
1 parent ca7e2e8 commit 349efca
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/blackbox/api/dds-pim/PubSubWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,13 @@ class PubSubWriter
return *this;
}

PubSubWriter& disable_heartbeat_piggyback(
bool value)
{
datawriter_qos_.reliable_writer_qos().disable_heartbeat_piggyback = value;
return *this;
}

PubSubWriter& max_blocking_time(
const eprosima::fastrtps::Duration_t time)
{
Expand Down
7 changes: 7 additions & 0 deletions test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,13 @@ class PubSubWriter
return *this;
}

PubSubWriter& disable_heartbeat_piggyback(
bool value)
{
publisher_attr_.qos.disable_heartbeat_piggyback = value;
return *this;
}

PubSubWriter& max_blocking_time(
const eprosima::fastrtps::Duration_t time)
{
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox/common/BlackboxTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ std::list<FixedSized> default_fixed_sized_data_generator(
std::list<KeyedHelloWorld> default_keyedhelloworld_data_generator(
size_t max = 0);

std::list<KeyedHelloWorld> uniquekey_keyedhelloworld_data_generator(
size_t max = 0);

std::list<String> default_large_string_data_generator(
size_t max = 0);

Expand Down
103 changes: 103 additions & 0 deletions test/blackbox/common/BlackboxTestsReliability.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "BlackboxTests.hpp"

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

#include <gtest/gtest.h>

#include <fastrtps/utils/TimeConversion.h>
#include <rtps/transport/test_UDPv4Transport.h>

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;
using test_UDPv4Transport = eprosima::fastdds::rtps::test_UDPv4Transport;
using test_UDPv4TransportDescriptor = eprosima::fastdds::rtps::test_UDPv4TransportDescriptor;

void reliability_disable_heartbeat_piggyback(
bool disable_heartbeat_piggyback)
{
PubSubReader<KeyedHelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<KeyedHelloWorldType> writer(TEST_TOPIC_NAME);

bool heartbeat_found = false;
bool start_reception = false;
EntityId_t writer_id;

auto testTransport = std::make_shared<test_UDPv4TransportDescriptor>();
testTransport->drop_heartbeat_messages_filter_ = [&heartbeat_found, &writer_id, &start_reception](CDRMessage_t& msg)
-> bool
{
if (start_reception)
{
auto old_pos = msg.pos;
EntityId_t writer_id_msg;
msg.pos += 4;
CDRMessage::readEntityId(&msg, &writer_id_msg);
if (writer_id == writer_id_msg)
{
heartbeat_found = true;
}
msg.pos = old_pos;
}
return false;
};

writer.reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS)
.history_kind(eprosima::fastrtps::KEEP_LAST_HISTORY_QOS)
.history_depth(1)
.heartbeat_period_seconds(180000)
.disable_heartbeat_piggyback(disable_heartbeat_piggyback)
.disable_builtin_transport()
.add_user_transport_to_pparams(testTransport)
.init();
writer_id = writer.datawriter_guid().entityId;

reader.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS)
.reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS)
.init();

ASSERT_TRUE(reader.isInitialized());
ASSERT_TRUE(writer.isInitialized());

// Wait for discovery.
writer.wait_discovery();
reader.wait_discovery();

std::this_thread::sleep_for(std::chrono::seconds(1));

auto data = uniquekey_keyedhelloworld_data_generator();
reader.startReception(data);
start_reception = true;
// Send data
writer.send(data);
// In this test all data should be sent.
ASSERT_TRUE(data.empty());
// Block reader until reception finished or timeout.
reader.block_for_all();

ASSERT_EQ(heartbeat_found, !disable_heartbeat_piggyback);
}

TEST(Reliability, DisableHeartbeatPiggybackFalse)
{
reliability_disable_heartbeat_piggyback(false);
}

TEST(Reliability, DisableHeartbeatPiggybackTrue)
{
reliability_disable_heartbeat_piggyback(true);
}
22 changes: 22 additions & 0 deletions test/blackbox/utils/data_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ std::list<KeyedHelloWorld> default_keyedhelloworld_data_generator(
return returnedValue;
}

std::list<KeyedHelloWorld> uniquekey_keyedhelloworld_data_generator(
size_t max)
{
uint16_t index = 0;
size_t maximum = max ? max : 10;
std::list<KeyedHelloWorld> returnedValue(maximum);

std::generate(returnedValue.begin(), returnedValue.end(), [&index]
{
KeyedHelloWorld hello;
hello.index(index);
hello.key(index + 1);
std::stringstream ss;
ss << "HelloWorld " << index;
hello.message(ss.str());
++index;
return hello;
});

return returnedValue;
}

std::list<String> default_large_string_data_generator(
size_t max)
{
Expand Down

0 comments on commit 349efca

Please sign in to comment.