Skip to content

Commit df74c92

Browse files
committed
Add tests for empty dispose messages
Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
1 parent 5465cb2 commit df74c92

3 files changed

Lines changed: 145 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ set(TEST_SOURCES
7474
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedTypeObjectSupport.cxx)
7575

7676
set(TEST_LIST
77-
end_to_end_local_communication_key_dispose)
77+
end_to_end_local_communication_key_dispose,
78+
end_to_end_local_communication_key_dispose_without_payload)
7879

7980
set(TEST_NEEDED_SOURCES
8081
)

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,101 @@ void test_local_communication_key_dispose(
170170
router.stop();
171171
}
172172

173+
174+
/**
175+
* Test communication between two DDS Participants hosted in the same device, but which are at different DDS domains.
176+
* This is accomplished by using a DDS Router instance with a Simple Participant deployed at each domain.
177+
*
178+
* The reliable option changes the test behavior to verify that the communication is reliable and all old data is sent
179+
* to Late Joiners.
180+
*
181+
* However, in this test the disposed key messages are sent without payload.
182+
*/
183+
void test_local_communication_key_dispose_without_payload(
184+
DdsRouterConfiguration ddsrouter_configuration,
185+
uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE,
186+
uint32_t time_between_samples = DEFAULT_MILLISECONDS_PUBLISH_LOOP,
187+
uint32_t msg_size = DEFAULT_MESSAGE_SIZE)
188+
{
189+
// Check there are no warnings/errors
190+
// TODO: Change threshold to \c Log::Kind::Warning once middleware warnings are solved
191+
// eprosima::ddsrouter::test::TestLogHandler test_log_handler(utils::Log::Kind::Error);
192+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
193+
194+
uint32_t samples_sent = 0;
195+
std::atomic<uint32_t> samples_received(0);
196+
197+
// Create a message with size specified by repeating the same string
198+
HelloWorldKeyed msg;
199+
HelloWorldKeyedZeroSizePayloadPubSubType type;
200+
201+
std::string msg_str;
202+
203+
// Add this string as many times as the msg size requires
204+
for (uint32_t i = 0; i < msg_size; i++)
205+
{
206+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
207+
}
208+
msg.message(msg_str);
209+
msg.id(666);
210+
211+
// Create DDS Publisher in domain 0
212+
TestPublisher<HelloWorldKeyed> publisher(type.is_compute_key_provided);
213+
214+
ASSERT_TRUE(publisher.init(0));
215+
216+
// Create DDS Subscriber in domain 1
217+
TestSubscriber<HelloWorldKeyed> subscriber(type.is_compute_key_provided);
218+
219+
ASSERT_TRUE(subscriber.init(1, &msg, &samples_received));
220+
221+
// Create DdsRouter entity
222+
// The DDS Router does not start here in order to test a reliable communication
223+
DdsRouter router(ddsrouter_configuration);
224+
225+
// Start DDS Router
226+
router.start();
227+
228+
// Start publishing
229+
while (samples_received.load() < samples_to_receive)
230+
{
231+
msg.index(++samples_sent);
232+
ASSERT_EQ(publisher.publish(msg), fastdds::dds::RETCODE_OK) << samples_sent;
233+
234+
// If time is 0 do not wait
235+
if (time_between_samples > 0)
236+
{
237+
std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples));
238+
}
239+
}
240+
241+
// All samples received, now dispose key from publisher and check that subscriber has receive it
242+
ASSERT_TRUE(publisher.dispose_key(msg) == fastdds::dds::RETCODE_OK);
243+
std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION));
244+
samples_received.store(0);
245+
246+
// Keep publishing
247+
while (samples_received.load() < samples_to_receive)
248+
{
249+
msg.index(++samples_sent);
250+
ASSERT_EQ(publisher.publish(msg), fastdds::dds::RETCODE_OK) << samples_sent;
251+
252+
// If time is 0 do not wait
253+
if (time_between_samples > 0)
254+
{
255+
std::this_thread::sleep_for(std::chrono::milliseconds(time_between_samples));
256+
}
257+
}
258+
259+
// All samples received, now dispose key from publisher and check that subscriber has receive it
260+
ASSERT_TRUE(publisher.dispose_key(msg) == fastdds::dds::RETCODE_OK);
261+
std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SUBSCRIBER_MESSAGE_RECEPTION));
262+
263+
ASSERT_EQ(2u, subscriber.n_disposed());
264+
265+
router.stop();
266+
}
267+
173268
} /* namespace test */
174269

175270
/**
@@ -181,6 +276,12 @@ TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose)
181276
test::dds_test_simple_configuration());
182277
}
183278

279+
TEST(DDSTestLocalDisposeKey, end_to_end_local_communication_key_dispose_without_payload)
280+
{
281+
test::test_local_communication_key_dispose_without_payload(
282+
test::dds_test_simple_configuration());
283+
}
284+
184285
int main(
185286
int argc,
186287
char** argv)

ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ namespace test {
5454

5555
constexpr const char* TOPIC_NAME = "DDS-Router-Test";
5656

57+
/**
58+
* Type support used to simulate payloads of zero size
59+
*/
60+
class HelloWorldKeyedZeroSizePayloadPubSubType: public HelloWorldKeyedPubSubType
61+
{
62+
using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t;
63+
64+
uint32_t calculate_serialized_size(
65+
const void* const data,
66+
DataRepresentationId_t data_representation) override
67+
{
68+
return 0;
69+
}
70+
71+
};
72+
5773
/**
5874
* Class used to group into a single working unit a Publisher with a DataWriter and a TypeSupport member corresponding
5975
* to the HelloWorld datatype
@@ -64,12 +80,14 @@ class TestPublisher
6480
public:
6581

6682
TestPublisher(
67-
bool keyed = false)
83+
bool keyed = false,
84+
bool zero_size = false)
6885
: participant_(nullptr)
6986
, publisher_(nullptr)
7087
, topic_(nullptr)
7188
, writer_(nullptr)
7289
, keyed_(keyed)
90+
, zero_size_(zero_size)
7391
{
7492
}
7593

@@ -102,7 +120,14 @@ class TestPublisher
102120
eprosima::fastdds::dds::TypeSupport type;
103121
if (keyed_)
104122
{
105-
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType());
123+
if(zero_size_)
124+
{
125+
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedZeroSizePayloadPubSubType());
126+
}
127+
else
128+
{
129+
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType());
130+
}
106131
}
107132
else
108133
{
@@ -191,6 +216,8 @@ class TestPublisher
191216

192217
bool keyed_;
193218

219+
bool zero_size_;
220+
194221
class PubListener : public eprosima::fastdds::dds::DataWriterListener
195222
{
196223
public:
@@ -271,13 +298,15 @@ class TestSubscriber
271298

272299
TestSubscriber(
273300
bool keyed = false,
274-
bool reliable = false)
301+
bool reliable = false,
302+
bool zero_size = false)
275303
: participant_(nullptr)
276304
, subscriber_(nullptr)
277305
, topic_(nullptr)
278306
, reader_(nullptr)
279307
, keyed_(keyed)
280308
, reliable_ (reliable)
309+
, zero_size_(zero_size)
281310
{
282311
}
283312

@@ -314,7 +343,14 @@ class TestSubscriber
314343
eprosima::fastdds::dds::TypeSupport type;
315344
if (keyed_)
316345
{
317-
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType());
346+
if(zero_size_)
347+
{
348+
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedZeroSizePayloadPubSubType());
349+
}
350+
else
351+
{
352+
type = eprosima::fastdds::dds::TypeSupport(new HelloWorldKeyedPubSubType());
353+
}
318354
}
319355
else
320356
{
@@ -391,6 +427,8 @@ class TestSubscriber
391427

392428
bool keyed_;
393429

430+
bool zero_size_;
431+
394432
bool reliable_;
395433

396434
/**

0 commit comments

Comments
 (0)