Skip to content

Commit b1aa00c

Browse files
cferreiragonzRookieCLY
authored andcommitted
Increase 'max_blocking_time' for services in Easy Mode (eProsima#5617)
* Refs #22721: Easy Mode XML Tests Signed-off-by: cferreiragonz <[email protected]> * Refs #22721: Increase max_blocking_time in Easy Mode Signed-off-by: cferreiragonz <[email protected]> * Refs #22721: Fix comments Signed-off-by: cferreiragonz <[email protected]> * Refs #22721: Review Signed-off-by: cferreiragonz <[email protected]> * Refs #22721: Fix Windows build Signed-off-by: cferreiragonz <[email protected]> --------- Signed-off-by: cferreiragonz <[email protected]> Signed-off-by: RookieCLY <[email protected]>
1 parent 38b4a74 commit b1aa00c

File tree

6 files changed

+143
-6
lines changed

6 files changed

+143
-6
lines changed

src/cpp/rtps/RTPSDomain.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ namespace eprosima {
5858
namespace fastdds {
5959
namespace rtps {
6060

61+
const char* EASY_MODE_SERVICE_PROFILE =
62+
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
63+
"<dds xmlns=\"http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles\">\n"
64+
" <profiles>\n"
65+
" <data_writer profile_name=\"service\">\n"
66+
" <qos>\n"
67+
" <reliability>\n"
68+
" <max_blocking_time>\n"
69+
" <sec>1</sec>\n"
70+
" <nanosec>0</nanosec>\n"
71+
" </max_blocking_time>\n"
72+
" </reliability>\n"
73+
" </qos>\n"
74+
" </data_writer>\n"
75+
" </profiles>\n"
76+
"</dds>\n";
77+
6178
template<typename _Descriptor>
6279
bool has_user_transport(
6380
const RTPSParticipantAttributes& att)
@@ -616,6 +633,22 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
616633
// Point to the well known DS port in the corresponding domain
617634
client_att.builtin.discovery_config.m_DiscoveryServers.push_back(locator_udp);
618635

636+
// Load the 'service' profile for ROS2_EASY_MODE services if there is no existing profile yet
637+
xmlparser::PublisherAttributes attr;
638+
auto ret_if = xmlparser::XMLProfileManager::fillPublisherAttributes("service", attr, false);
639+
if (ret_if == xmlparser::XMLP_ret::XML_ERROR)
640+
{
641+
// An XML_ERROR is returned if there is no existing profile for the given name
642+
xmlparser::XMLProfileManager::loadXMLString(EASY_MODE_SERVICE_PROFILE, strlen(EASY_MODE_SERVICE_PROFILE));
643+
EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Loaded service profile for ROS2_EASY_MODE servers");
644+
}
645+
else
646+
{
647+
// There is already a profile with the given name. Do not overwrite it
648+
EPROSIMA_LOG_WARNING(RTPS_DOMAIN, "An XML profile for 'service' was found. When using ROS2_EASY_MODE, please ensure"
649+
" the max_blocking_time is configured with a value higher than the default.");
650+
}
651+
619652
SystemCommandBuilder sys_command;
620653
int res = sys_command.executable(FAST_DDS_DEFAULT_CLI_SCRIPT_NAME)
621654
.verb(FAST_DDS_DEFAULT_CLI_DISCOVERY_VERB)

test/blackbox/common/BlackboxTestsTransportCustom.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ TEST(ChainingTransportTests, builtin_transports_env_large_data)
613613
}
614614

615615
/**
616-
* DS Auto transport shall always be used along with ROS_DISCOVERY_SERVER=AUTO.
616+
* P2P transport shall always be used along with ROS2_EASY_MODE.
617617
* This is due to the working principle of the mode. If it is not specified,
618618
* the background discovery server will not be launched and the test will never
619619
* finish since both clients will keep waiting for it.

test/blackbox/common/DDSBlackboxTestsDSEasyMode.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TEST(DSEasyMode, easy_discovery_mode_env_correctly_launches)
5858
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
5959
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
6060

61-
// Setting ROS_DISCOVERY_SERVER to AUTO
61+
// Setting ROS2_EASY_MODE
6262
// Configures as SUPER_CLIENT SHM and TCP
6363
set_easy_discovery_mode_env();
6464

@@ -136,8 +136,7 @@ TEST(DSEasyMode, easy_discovery_mode_env_correct_transports_are_used)
136136

137137
ASSERT_TRUE(writer_udp.isInitialized());
138138

139-
// Setting ROS_DISCOVERY_SERVER to AUTO
140-
// Configures as SUPER_CLIENT SHM and TCP
139+
// Setting ROS2_EASY_MODE configures as SUPER_CLIENT SHM and TCP
141140
set_easy_discovery_mode_env();
142141

143142
std::atomic<bool> locators_match_p2p_transport(true);
@@ -226,7 +225,7 @@ TEST(DSEasyMode, easy_discovery_mode_env_discovery_info)
226225
ASSERT_TRUE(writers.back()->isInitialized());
227226
}
228227

229-
// Setting ROS_DISCOVERY_SERVER to AUTO
228+
// Setting ROS2_EASY_MODE
230229
// Configures as SUPER_CLIENT SHM and TCP
231230
set_easy_discovery_mode_env();
232231

@@ -266,7 +265,7 @@ TEST(DSEasyMode, easy_discovery_mode_env_multiple_clients_multiple_domains)
266265
std::vector<std::shared_ptr<PubSubWriter<HelloWorldPubSubType>>> writers;
267266
std::vector<std::shared_ptr<PubSubReader<HelloWorldPubSubType>>> readers;
268267

269-
// Setting ROS_DISCOVERY_SERVER to AUTO
268+
// Setting ROS2_EASY_MODE
270269
// Configures as SUPER_CLIENT SHM and TCP
271270
set_easy_discovery_mode_env();
272271

test/unittest/dds/participant/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../profiles/test_xml_profile.xml
1616
${CMAKE_CURRENT_BINARY_DIR}/test_xml_profile.xml
1717
COPYONLY)
1818

19+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../profiles/test_xml_service_easy_mode.xml
20+
${CMAKE_CURRENT_BINARY_DIR}/test_xml_service_easy_mode.xml
21+
COPYONLY)
22+
1923
set(PARTICIPANTTESTS_SOURCE
2024
ParticipantTests.cpp
2125
)

test/unittest/dds/participant/ParticipantTests.cpp

+83
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
#define GET_PID getpid
8282
#endif // if defined(_WIN32)
8383

84+
void stop_background_servers()
85+
{
86+
#ifndef _WIN32 // The feature is not supported on Windows yet
87+
// Stop server(s)
88+
int res = std::system("fastdds discovery stop");
89+
ASSERT_EQ(res, 0);
90+
#endif // _WIN32
91+
}
8492

8593
namespace eprosima {
8694
namespace fastdds {
@@ -1077,6 +1085,17 @@ void set_environment_variable(
10771085
#endif // _WIN32
10781086
}
10791087

1088+
void set_easy_mode_environment_variable(
1089+
const std::string ip = "127.0.0.1"
1090+
)
1091+
{
1092+
#ifdef _WIN32
1093+
ASSERT_EQ(0, _putenv_s(rtps::EASY_MODE_URI, ip.c_str()));
1094+
#else
1095+
ASSERT_EQ(0, setenv(rtps::EASY_MODE_URI, ip.c_str(), 1));
1096+
#endif // _WIN32
1097+
}
1098+
10801099
void set_environment_file(
10811100
const std::string& filename)
10821101
{
@@ -1483,6 +1502,70 @@ TEST(ParticipantTests, ServerParticipantRemoteServerListConfiguration)
14831502
EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant));
14841503
}
14851504

1505+
TEST(ParticipantTests, EasyModeParticipantLoadsServiceDataWriterQos)
1506+
{
1507+
// Use get_datawriter_qos_from_profile to check if the profile is correctly loaded.
1508+
{
1509+
// Default participant
1510+
DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(
1511+
(uint32_t)GET_PID() % 230, PARTICIPANT_QOS_DEFAULT);
1512+
ASSERT_NE(nullptr, participant);
1513+
Publisher* default_publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT);
1514+
ASSERT_NE(default_publisher, nullptr);
1515+
DataWriterQos dw_qos;
1516+
EXPECT_EQ(default_publisher->get_datawriter_qos_from_profile("service", dw_qos), RETCODE_BAD_PARAMETER);
1517+
1518+
EXPECT_EQ(RETCODE_OK, participant->delete_publisher(default_publisher));
1519+
EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant));
1520+
}
1521+
1522+
{
1523+
// Easy mode participant
1524+
set_easy_mode_environment_variable();
1525+
DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(
1526+
(uint32_t)GET_PID() % 230, PARTICIPANT_QOS_DEFAULT);
1527+
ASSERT_NE(nullptr, participant);
1528+
Publisher* easy_mode_publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT);
1529+
ASSERT_NE(easy_mode_publisher, nullptr);
1530+
DataWriterQos dw_qos;
1531+
EXPECT_EQ(easy_mode_publisher->get_datawriter_qos_from_profile("service", dw_qos), RETCODE_OK);
1532+
EXPECT_EQ(dw_qos.reliability().max_blocking_time.seconds, 1); // Easy Mode value
1533+
EXPECT_EQ(dw_qos.reliability().max_blocking_time.nanosec, 0u); // Easy Mode value
1534+
EXPECT_EQ(dw_qos.durability().kind, TRANSIENT_LOCAL_DURABILITY_QOS); // Default value
1535+
1536+
EXPECT_EQ(RETCODE_OK, participant->delete_publisher(easy_mode_publisher));
1537+
EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant));
1538+
stop_background_servers();
1539+
}
1540+
}
1541+
1542+
TEST(ParticipantTests, EasyModeParticipantDoNotOverwriteCustomDataWriterQos)
1543+
{
1544+
{
1545+
// Easy mode participant with existing profile
1546+
// Set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_service_easy_mode.xml"
1547+
eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_service_easy_mode.xml");
1548+
set_easy_mode_environment_variable();
1549+
DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(
1550+
(uint32_t)GET_PID() % 230, PARTICIPANT_QOS_DEFAULT);
1551+
ASSERT_NE(nullptr, participant);
1552+
Publisher* easy_mode_publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT);
1553+
ASSERT_NE(easy_mode_publisher, nullptr);
1554+
PublisherQos profile_qos;
1555+
EXPECT_EQ(easy_mode_publisher->get_participant()->get_publisher_qos_from_profile("service", profile_qos),
1556+
RETCODE_OK);
1557+
DataWriterQos dw_qos;
1558+
easy_mode_publisher->get_datawriter_qos_from_profile("service", dw_qos);
1559+
EXPECT_EQ(dw_qos.reliability().max_blocking_time.seconds, 5); // XML value
1560+
EXPECT_EQ(dw_qos.reliability().max_blocking_time.nanosec, 0u); // XML value
1561+
EXPECT_EQ(dw_qos.durability().kind, VOLATILE_DURABILITY_QOS); // XML value
1562+
1563+
EXPECT_EQ(RETCODE_OK, participant->delete_publisher(easy_mode_publisher));
1564+
EXPECT_EQ(RETCODE_OK, DomainParticipantFactory::get_instance()->delete_participant(participant));
1565+
stop_background_servers();
1566+
}
1567+
}
1568+
14861569
/**
14871570
* Dynamic modification of servers. Replacing previous servers with new ones.
14881571
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<dds xmlns="http://www.eprosima.com">
3+
<profiles>
4+
<data_writer profile_name="service">
5+
<qos>
6+
<reliability>
7+
<max_blocking_time>
8+
<sec>5</sec>
9+
<nanosec>0</nanosec>
10+
</max_blocking_time>
11+
</reliability>
12+
<durability>
13+
<kind>VOLATILE</kind>
14+
</durability>
15+
</qos>
16+
</data_writer>
17+
</profiles>
18+
</dds>

0 commit comments

Comments
 (0)