|
17 | 17 | #include "PubSubReader.hpp"
|
18 | 18 | #include "PubSubWriter.hpp"
|
19 | 19 |
|
| 20 | +#include <fastrtps/transport/test_UDPv4TransportDescriptor.h> |
| 21 | + |
20 | 22 | TEST(KeyedTopic, RegistrationNonKeyedFail)
|
21 | 23 | {
|
22 | 24 | PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
|
@@ -181,6 +183,105 @@ TEST(KeyedTopic, UnregisterWhenHistoryKeepAll)
|
181 | 183 | ASSERT_TRUE(writer.unregister_instance(data.back(), instance_handle_2));
|
182 | 184 | }
|
183 | 185 |
|
| 186 | +// Regression test for redmine issue #20239 |
| 187 | +TEST(KeyedTopic, DataWriterAlwaysSendTheSerializedKeyViaInlineQoS) |
| 188 | +{ |
| 189 | + PubSubWriter<KeyedHelloWorldPubSubType> writer(TEST_TOPIC_NAME); |
| 190 | + PubSubReader<KeyedHelloWorldPubSubType> reader(TEST_TOPIC_NAME); |
| 191 | + |
| 192 | + auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>(); |
| 193 | + |
| 194 | + bool writer_sends_inline_qos = true; |
| 195 | + bool writer_sends_pid_key_hash = true; |
| 196 | + |
| 197 | + testTransport->drop_data_messages_filter_ = [&writer_sends_inline_qos, |
| 198 | + &writer_sends_pid_key_hash](eprosima::fastrtps::rtps::CDRMessage_t& msg) -> bool |
| 199 | + { |
| 200 | + // Check for inline_qos |
| 201 | + uint8_t flags = msg.buffer[msg.pos - 3]; |
| 202 | + auto old_pos = msg.pos; |
| 203 | + |
| 204 | + // Skip extraFlags, read octetsToInlineQos, and calculate inline qos position. |
| 205 | + msg.pos += 2; |
| 206 | + uint16_t to_inline_qos = 0; |
| 207 | + eprosima::fastrtps::rtps::CDRMessage::readUInt16(&msg, &to_inline_qos); |
| 208 | + uint32_t inline_qos_pos = msg.pos + to_inline_qos; |
| 209 | + |
| 210 | + // Filters are only applied to user data |
| 211 | + // no need to check if the packets comer from a builtin |
| 212 | + |
| 213 | + writer_sends_inline_qos &= static_cast<bool>((flags & (1 << 1))); |
| 214 | + |
| 215 | + // Stop seeking if inline qos are not present |
| 216 | + // Fail the test afterwards |
| 217 | + if (!writer_sends_inline_qos) |
| 218 | + { |
| 219 | + return false; |
| 220 | + } |
| 221 | + else |
| 222 | + { |
| 223 | + // Process inline qos |
| 224 | + msg.pos = inline_qos_pos; |
| 225 | + bool key_hash_was_found = false; |
| 226 | + while (msg.pos < msg.length) |
| 227 | + { |
| 228 | + uint16_t pid = 0; |
| 229 | + uint16_t plen = 0; |
| 230 | + |
| 231 | + eprosima::fastrtps::rtps::CDRMessage::readUInt16(&msg, &pid); |
| 232 | + eprosima::fastrtps::rtps::CDRMessage::readUInt16(&msg, &plen); |
| 233 | + uint32_t next_pos = msg.pos + plen; |
| 234 | + |
| 235 | + if (pid == eprosima::fastdds::dds::PID_KEY_HASH) |
| 236 | + { |
| 237 | + key_hash_was_found = true; |
| 238 | + } |
| 239 | + else if (pid == eprosima::fastdds::dds::PID_SENTINEL) |
| 240 | + { |
| 241 | + break; |
| 242 | + } |
| 243 | + |
| 244 | + msg.pos = next_pos; |
| 245 | + } |
| 246 | + |
| 247 | + writer_sends_pid_key_hash &= key_hash_was_found; |
| 248 | + msg.pos = old_pos; |
| 249 | + } |
| 250 | + |
| 251 | + // Do not drop the packet in any case |
| 252 | + return false; |
| 253 | + }; |
| 254 | + |
| 255 | + writer. |
| 256 | + disable_builtin_transport(). |
| 257 | + add_user_transport_to_pparams(testTransport). |
| 258 | + init(); |
| 259 | + |
| 260 | + ASSERT_TRUE(writer.isInitialized()); |
| 261 | + |
| 262 | + reader. |
| 263 | + expect_inline_qos(false). |
| 264 | + init(); |
| 265 | + |
| 266 | + ASSERT_TRUE(reader.isInitialized()); |
| 267 | + |
| 268 | + // Wait for discovery. |
| 269 | + writer.wait_discovery(); |
| 270 | + reader.wait_discovery(); |
| 271 | + |
| 272 | + auto data = default_keyedhelloworld_data_generator(5); |
| 273 | + |
| 274 | + reader.startReception(data); |
| 275 | + writer.send(data); |
| 276 | + |
| 277 | + // In this test all data should be sent. |
| 278 | + EXPECT_TRUE(data.empty()); |
| 279 | + reader.block_for_all(); |
| 280 | + |
| 281 | + EXPECT_TRUE(writer_sends_inline_qos); |
| 282 | + EXPECT_TRUE(writer_sends_pid_key_hash); |
| 283 | +} |
| 284 | + |
184 | 285 | /* Uncomment when DDS API supports NO_WRITERS_ALIVE
|
185 | 286 | TEST(KeyedTopic, WriteSamplesBestEffort)
|
186 | 287 | {
|
|
0 commit comments