@@ -2242,6 +2242,88 @@ TEST(OwnershipQos, exclusive_kind_keep_all_reliable)
2242
2242
reader.block_for_all ();
2243
2243
}
2244
2244
2245
+ /* !
2246
+ * This is a regression test for redmine issue 20866.
2247
+ *
2248
+ * This test checks that a reader with a KEEP_ALL history and an exclusive ownership policy only does not return
2249
+ * data from the writer with the lowest strength after returning data from the highest one.
2250
+ */
2251
+ TEST (OwnershipQos, exclusive_kind_keep_all_reliable_mixed)
2252
+ {
2253
+ PubSubReader<KeyedHelloWorldPubSubType> reader (TEST_TOPIC_NAME);
2254
+ PubSubWriter<KeyedHelloWorldPubSubType> low_strength_writer (TEST_TOPIC_NAME);
2255
+ PubSubWriter<KeyedHelloWorldPubSubType> high_strength_writer (TEST_TOPIC_NAME);
2256
+
2257
+ // Prepare data.
2258
+ std::list<KeyedHelloWorld> generated_data = default_keyedhelloworld_data_generator (20 );
2259
+ auto middle = std::next (generated_data.begin (), 10 );
2260
+ std::list<KeyedHelloWorld> low_strength_data (generated_data.begin (), middle);
2261
+ std::list<KeyedHelloWorld> high_strength_data (middle, generated_data.end ());
2262
+ auto expected_data = high_strength_data;
2263
+ auto it = low_strength_data.begin ();
2264
+ // Expect reception of the first two samples from the low strength writer (one per instance).
2265
+ expected_data.push_front (*it++);
2266
+ expected_data.push_front (*it);
2267
+
2268
+ // Initialize writers.
2269
+ low_strength_writer.ownership_strength (3 )
2270
+ .history_kind (eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS)
2271
+ .reliability (eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
2272
+ .init ();
2273
+ ASSERT_TRUE (low_strength_writer.isInitialized ());
2274
+
2275
+ // High strength writer will use a custom transport to ensure its data is received after the low strength data.
2276
+ auto test_transport = std::make_shared<test_UDPv4TransportDescriptor>();
2277
+ std::atomic<bool > drop_messages (false );
2278
+ test_transport->messages_filter_ = [&drop_messages](eprosima::fastdds::rtps::CDRMessage_t&)
2279
+ {
2280
+ return drop_messages.load ();
2281
+ };
2282
+ high_strength_writer.ownership_strength (4 )
2283
+ .history_kind (eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS)
2284
+ .reliability (eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
2285
+ .disable_builtin_transport ()
2286
+ .add_user_transport_to_pparams (test_transport)
2287
+ .init ();
2288
+ ASSERT_TRUE (high_strength_writer.isInitialized ());
2289
+
2290
+ // Initialize reader.
2291
+ reader.ownership_exclusive ()
2292
+ .history_kind (eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS)
2293
+ .reliability (eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
2294
+ .init ();
2295
+ ASSERT_TRUE (reader.isInitialized ());
2296
+
2297
+ // Wait for discovery.
2298
+ low_strength_writer.wait_discovery ();
2299
+ high_strength_writer.wait_discovery ();
2300
+ reader.wait_discovery (std::chrono::seconds::zero (), 2 );
2301
+
2302
+ // Drop the messages from the high strength writer, so they arrive later to the reader.
2303
+ drop_messages.store (true );
2304
+
2305
+ // Send one sample from each writer, with low strength data first.
2306
+ while (!low_strength_data.empty () && !high_strength_data.empty ())
2307
+ {
2308
+ EXPECT_TRUE (low_strength_writer.send_sample (low_strength_data.front ()));
2309
+ EXPECT_TRUE (high_strength_writer.send_sample (high_strength_data.front ()));
2310
+ low_strength_data.pop_front ();
2311
+ high_strength_data.pop_front ();
2312
+ }
2313
+
2314
+ // Wait for the reader to receive the low strength data.
2315
+ EXPECT_TRUE (low_strength_writer.waitForAllAcked (std::chrono::seconds (1 )));
2316
+
2317
+ // Let high strength writer send the data, and wait for the reader to receive it.
2318
+ drop_messages.store (false );
2319
+ EXPECT_TRUE (high_strength_writer.waitForAllAcked (std::chrono::seconds (1 )));
2320
+
2321
+ // Make the reader process the data, expecting only the high strength data.
2322
+ // The issue was reproduced by the reader complaining about reception of unexpected data.
2323
+ reader.startReception (expected_data);
2324
+ reader.block_for_all ();
2325
+ }
2326
+
2245
2327
#ifdef INSTANTIATE_TEST_SUITE_P
2246
2328
#define GTEST_INSTANTIATE_TEST_MACRO (x, y, z, w ) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
2247
2329
#else
0 commit comments