Skip to content

Commit f985fde

Browse files
Fix original_writer flaky test (#528)
* Fix flakytest due to dirty memory Signed-off-by: Emilio Cuesta <[email protected]> * uncrustify Signed-off-by: Emilio Cuesta <[email protected]> * Separating og writer test into three specific tests Signed-off-by: Emilio Cuesta <[email protected]> * uncrustify Signed-off-by: Emilio Cuesta <[email protected]> --------- Signed-off-by: Emilio Cuesta <[email protected]>
1 parent 2514eb9 commit f985fde

File tree

2 files changed

+107
-11
lines changed

2 files changed

+107
-11
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: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,12 @@ 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(
214+
void test_original_writer_forwarding_unset(
211215
DdsRouterConfiguration ddsrouter_configuration)
212216
{
213217
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
@@ -233,34 +237,104 @@ void test_original_writer_forwarding(
233237
DdsRouter router(ddsrouter_configuration);
234238
router.start();
235239

236-
// CASE 1: Send message without original_writer_param, should be set to writers guid
240+
// CASE: Send message without original_writer_param, it should be set to the original writers guid
241+
// in the router either way
237242
sent_msg.index(++samples_sent);
238243
ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK);
239244
// Watiting for the message to be received
240245
while (samples_received.load() < 1)
241246
{
242247
}
248+
243249
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
244250

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

257-
// CASE 3: Send message with original_writer_param set to unknown, should be set to other value
297+
router.stop();
298+
}
299+
300+
/**
301+
* This test checks that, when the original writer parameter is populated by a writer and
302+
* is equal to unknown, the router populates it with the original writer's GUID when forwarding the message.
303+
*/
304+
template <class MsgStruct, class MsgStructType>
305+
void test_original_writer_forwarding_unknown(
306+
DdsRouterConfiguration ddsrouter_configuration)
307+
{
308+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
309+
310+
uint32_t samples_sent = 0;
311+
std::atomic<uint32_t> samples_received(0);
312+
313+
MsgStruct sent_msg;
314+
MsgStructType type;
315+
std::string msg_str;
316+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
317+
sent_msg.message(msg_str);
318+
// Create DDS Publisher in domain 0
319+
TestPublisher<MsgStruct> publisher(type.is_compute_key_provided);
320+
321+
ASSERT_TRUE(publisher.init(0));
322+
323+
// Create DDS Subscriber in domain 1
324+
TestSubscriber<MsgStruct> subscriber(type.is_compute_key_provided, true);
325+
ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received));
326+
327+
// Create DdsRouter entity
328+
DdsRouter router(ddsrouter_configuration);
329+
router.start();
330+
331+
// CASE: Send message with original_writer_param set to unknown, should be set to other value
258332
sent_msg.index(++samples_sent);
259333
eprosima::fastdds::rtps::WriteParams params;
260334
params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown());
261335
ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK);
262336
// Waiting for the message to be received
263-
while (samples_received.load() < 3)
337+
while (samples_received.load() < 1)
264338
{
265339
}
266340
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
@@ -385,12 +459,32 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami
385459
}
386460

387461
/**
388-
* Test original writer forwarding in HelloWorld topic between two DDS participants created in different domains,
389-
* by using a router with two Simple Participants at each domain.
462+
* This test checks that, when the original writer parameter is not set by a writer,
463+
* the router still sets it to the original writer's GUID when forwarding the message.
464+
*/
465+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unset)
466+
{
467+
test::test_original_writer_forwarding_unset<HelloWorld, HelloWorldPubSubType>(
468+
test::dds_test_simple_configuration());
469+
}
470+
471+
/**
472+
* This test checks that, when the original writer parameter is populated by a writer and
473+
* is not equal to unknown, the router keeps that value when forwarding the message.
474+
*/
475+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_populated)
476+
{
477+
test::test_original_writer_forwarding_populated<HelloWorld, HelloWorldPubSubType>(
478+
test::dds_test_simple_configuration());
479+
}
480+
481+
/**
482+
* This test checks that, when the original writer parameter is populated by a writer and
483+
* is equal to unknown, the router populates it with the original writer's GUID when forwarding the message.
390484
*/
391-
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding)
485+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unknown)
392486
{
393-
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
487+
test::test_original_writer_forwarding_unknown<HelloWorld, HelloWorldPubSubType>(
394488
test::dds_test_simple_configuration());
395489
}
396490

0 commit comments

Comments
 (0)