Skip to content

Commit af9b54f

Browse files
committed
Separating og writer test into three specific tests
Signed-off-by: Emilio Cuesta <[email protected]>
1 parent cc7d2fa commit af9b54f

File tree

2 files changed

+127
-47
lines changed

2 files changed

+127
-47
lines changed

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ set(TEST_LIST
3838
end_to_end_local_communication_high_throughput
3939
end_to_end_local_communication_transient_local
4040
end_to_end_local_communication_transient_local_disable_dynamic_discovery,
41-
end_to_end_local_communication_original_writer_forwarding)
41+
end_to_end_local_communication_original_writer_forwarding_unset,
42+
end_to_end_local_communication_original_writer_forwarding_populated,
43+
end_to_end_local_communication_original_writer_forwarding_unknown)
4244

4345
set(TEST_NEEDED_SOURCES
4446
)

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp

Lines changed: 124 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,13 @@ void test_local_communication(
206206
router.stop();
207207
}
208208

209+
/**
210+
* This test checks that, when the original writer parameter is not set by a writer,
211+
* the router still sets it to the original writer's GUID when forwarding the message.
212+
*/
209213
template <class MsgStruct, class MsgStructType>
210-
void test_original_writer_forwarding(
211-
DdsRouterConfiguration ddsrouter_configuration,
212-
int case_number)
214+
void test_original_writer_forwarding_unset(
215+
DdsRouterConfiguration ddsrouter_configuration)
213216
{
214217
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
215218

@@ -234,46 +237,105 @@ void test_original_writer_forwarding(
234237
DdsRouter router(ddsrouter_configuration);
235238
router.start();
236239

237-
// CASE 1: Send message without original_writer_param, should be set to writers guid
238-
if (case_number == 1)
239-
{
240-
sent_msg.index(++samples_sent);
241-
ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK);
242-
// Watiting for the message to be received
243-
while (samples_received.load() < 1)
244-
{
245-
}
246-
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
247-
}
240+
// CASE: Send message without original_writer_param, it should be set to the original writers guid
241+
// in the router either way
242+
sent_msg.index(++samples_sent);
243+
ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK);
244+
// Watiting for the message to be received
245+
while (samples_received.load() < 1);
246+
247+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
248+
249+
router.stop();
250+
}
248251

249-
// CASE 2: Send message with original_writer_param set to some value, value must be kept
250-
if (case_number == 2)
252+
/**
253+
* This test checks that, when the original writer parameter is populated by a writer and
254+
* is not equal to unknown, the router keeps that value when forwarding the message.
255+
*/
256+
template <class MsgStruct, class MsgStructType>
257+
void test_original_writer_forwarding_populated(
258+
DdsRouterConfiguration ddsrouter_configuration)
259+
{
260+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
261+
262+
uint32_t samples_sent = 0;
263+
std::atomic<uint32_t> samples_received(0);
264+
265+
MsgStruct sent_msg;
266+
MsgStructType type;
267+
std::string msg_str;
268+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
269+
sent_msg.message(msg_str);
270+
// Create DDS Publisher in domain 0
271+
TestPublisher<MsgStruct> publisher(type.is_compute_key_provided);
272+
273+
ASSERT_TRUE(publisher.init(0));
274+
275+
// Create DDS Subscriber in domain 1
276+
TestSubscriber<MsgStruct> subscriber(type.is_compute_key_provided, true);
277+
ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received));
278+
279+
// Create DdsRouter entity
280+
DdsRouter router(ddsrouter_configuration);
281+
router.start();
282+
283+
// CASE: Send message with original_writer_param set to some value distinct to unknown, value must be kept
284+
sent_msg.index(++samples_sent);
285+
eprosima::fastdds::rtps::WriteParams params_with_og_writer;
286+
eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678);
287+
params_with_og_writer.original_writer_info().original_writer_guid(guid);
288+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK);
289+
// Waiting for the message to be received
290+
while (samples_received.load() < 1)
251291
{
252-
sent_msg.index(++samples_sent);
253-
eprosima::fastdds::rtps::WriteParams params_with_og_writer;
254-
eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678);
255-
params_with_og_writer.original_writer_info().original_writer_guid(guid);
256-
ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK);
257-
// Waiting for the message to be received
258-
while (samples_received.load() < 1)
259-
{
260-
}
261-
ASSERT_EQ(subscriber.original_writer_guid(), guid);
262292
}
293+
ASSERT_EQ(subscriber.original_writer_guid(), guid);
294+
295+
router.stop();
296+
}
263297

264-
// CASE 3: Send message with original_writer_param set to unknown, should be set to other value
265-
if (case_number == 3)
298+
/**
299+
* This test checks that, when the original writer parameter is populated by a writer and
300+
* is equal to unknown, the router populates it with the original writer's GUID when forwarding the message.
301+
*/
302+
template <class MsgStruct, class MsgStructType>
303+
void test_original_writer_forwarding_unknown(
304+
DdsRouterConfiguration ddsrouter_configuration)
305+
{
306+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
307+
308+
uint32_t samples_sent = 0;
309+
std::atomic<uint32_t> samples_received(0);
310+
311+
MsgStruct sent_msg;
312+
MsgStructType type;
313+
std::string msg_str;
314+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
315+
sent_msg.message(msg_str);
316+
// Create DDS Publisher in domain 0
317+
TestPublisher<MsgStruct> publisher(type.is_compute_key_provided);
318+
319+
ASSERT_TRUE(publisher.init(0));
320+
321+
// Create DDS Subscriber in domain 1
322+
TestSubscriber<MsgStruct> subscriber(type.is_compute_key_provided, true);
323+
ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received));
324+
325+
// Create DdsRouter entity
326+
DdsRouter router(ddsrouter_configuration);
327+
router.start();
328+
329+
// CASE: Send message with original_writer_param set to unknown, should be set to other value
330+
sent_msg.index(++samples_sent);
331+
eprosima::fastdds::rtps::WriteParams params;
332+
params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown());
333+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK);
334+
// Waiting for the message to be received
335+
while (samples_received.load() < 1)
266336
{
267-
sent_msg.index(++samples_sent);
268-
eprosima::fastdds::rtps::WriteParams params;
269-
params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown());
270-
ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK);
271-
// Waiting for the message to be received
272-
while (samples_received.load() < 1)
273-
{
274-
}
275-
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
276337
}
338+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
277339

278340
router.stop();
279341
}
@@ -395,17 +457,33 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami
395457
}
396458

397459
/**
398-
* Test original writer forwarding in HelloWorld topic between two DDS participants created in different domains,
399-
* by using a router with two Simple Participants at each domain.
460+
* This test checks that, when the original writer parameter is not set by a writer,
461+
* the router still sets it to the original writer's GUID when forwarding the message.
400462
*/
401-
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding)
463+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unset)
402464
{
403-
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
404-
test::dds_test_simple_configuration(), 1);
405-
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
406-
test::dds_test_simple_configuration(), 2);
407-
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
408-
test::dds_test_simple_configuration(), 3);
465+
test::test_original_writer_forwarding_unset<HelloWorld, HelloWorldPubSubType>(
466+
test::dds_test_simple_configuration());
467+
}
468+
469+
/**
470+
* This test checks that, when the original writer parameter is populated by a writer and
471+
* is not equal to unknown, the router keeps that value when forwarding the message.
472+
*/
473+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_populated)
474+
{
475+
test::test_original_writer_forwarding_populated<HelloWorld, HelloWorldPubSubType>(
476+
test::dds_test_simple_configuration());
477+
}
478+
479+
/**
480+
* This test checks that, when the original writer parameter is populated by a writer and
481+
* is equal to unknown, the router populates it with the original writer's GUID when forwarding the message.
482+
*/
483+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unknown)
484+
{
485+
test::test_original_writer_forwarding_unknown<HelloWorld, HelloWorldPubSubType>(
486+
test::dds_test_simple_configuration());
409487
}
410488

411489
int main(

0 commit comments

Comments
 (0)