diff --git a/include/fastdds/rtps/transport/test_UDPv4TransportDescriptor.h b/include/fastdds/rtps/transport/test_UDPv4TransportDescriptor.h index 054a1bbbe3e..5c13ec1ae5f 100644 --- a/include/fastdds/rtps/transport/test_UDPv4TransportDescriptor.h +++ b/include/fastdds/rtps/transport/test_UDPv4TransportDescriptor.h @@ -38,7 +38,7 @@ struct test_UDPv4TransportDescriptor : public SocketTransportDescriptor //! Test shim parameters //! Percentage of data messages being dropped - uint8_t dropDataMessagesPercentage; + mutable std::atomic dropDataMessagesPercentage; //! Filtering function for dropping data messages filter drop_data_messages_filter_; //! Flag to enable dropping of discovery Participant DATA(P) messages @@ -48,24 +48,24 @@ struct test_UDPv4TransportDescriptor : public SocketTransportDescriptor //! Flag to enable dropping of discovery Reader DATA(R) messages bool dropSubscriptionBuiltinTopicData; //! Percentage of data fragments being dropped - uint8_t dropDataFragMessagesPercentage; + mutable std::atomic dropDataFragMessagesPercentage; //! Filtering function for dropping data fragments messages filter drop_data_frag_messages_filter_; //! Percentage of heartbeats being dropped - uint8_t dropHeartbeatMessagesPercentage; + mutable std::atomic dropHeartbeatMessagesPercentage; //! Filtering function for dropping heartbeat messages filter drop_heartbeat_messages_filter_; //! Percentage of AckNacks being dropped - uint8_t dropAckNackMessagesPercentage; + mutable std::atomic dropAckNackMessagesPercentage; //! Filtering function for dropping AckNacks filter drop_ack_nack_messages_filter_; //! Percentage of gap messages being dropped - uint8_t dropGapMessagesPercentage; + mutable std::atomic dropGapMessagesPercentage; //! Filtering function for dropping gap messages filter drop_gap_messages_filter_; // General drop percentage (indiscriminate) - uint8_t percentageOfMessagesToDrop; + mutable std::atomic percentageOfMessagesToDrop; // General filtering function for all kind of messages (indiscriminate) filter messages_filter_; diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.cpp b/src/cpp/rtps/transport/test_UDPv4Transport.cpp index e680b888451..929b613edcf 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.cpp +++ b/src/cpp/rtps/transport/test_UDPv4Transport.cpp @@ -492,7 +492,7 @@ bool test_UDPv4Transport::log_drop( bool test_UDPv4Transport::should_be_dropped( PercentageData* percent) { - percent->accumulator += percent->percentage; + percent->accumulator += percent->percentage.load(); if (percent->accumulator >= 100u) { percent->accumulator -= 100u; diff --git a/src/cpp/rtps/transport/test_UDPv4Transport.h b/src/cpp/rtps/transport/test_UDPv4Transport.h index 93a611675fc..c6c6b3b50b1 100644 --- a/src/cpp/rtps/transport/test_UDPv4Transport.h +++ b/src/cpp/rtps/transport/test_UDPv4Transport.h @@ -73,13 +73,13 @@ class test_UDPv4Transport : public UDPv4Transport struct PercentageData { PercentageData( - uint8_t percent) + std::atomic& percent) : percentage(percent) , accumulator(0) { } - uint8_t percentage; + std::atomic& percentage; uint8_t accumulator; }; diff --git a/test/blackbox/common/BlackboxTestsPubSubHistory.cpp b/test/blackbox/common/BlackboxTestsPubSubHistory.cpp index 29317c463dd..a09438c3db9 100644 --- a/test/blackbox/common/BlackboxTestsPubSubHistory.cpp +++ b/test/blackbox/common/BlackboxTestsPubSubHistory.cpp @@ -992,6 +992,11 @@ TEST_P(PubSubHistory, PubSubAsReliableKeepLastWithKeyUnorderedReception) writer.send(data); ASSERT_TRUE(data.empty()); + reader.block_for_at_least(static_cast(keys * depth * 0.1)); + + //! Avoid dropping deterministically the same re-sent samples + testTransport->dropDataMessagesPercentage.store(10); + reader.block_for_all(); reader.stopReception(); }