Skip to content

Commit bc1a8c2

Browse files
committed
Refs #23432. Improve TRP-FUN-03 test.
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 3c7a04f commit bc1a8c2

File tree

1 file changed

+82
-7
lines changed

1 file changed

+82
-7
lines changed

test/blackbox/common/DDSBlackboxTestsDataWriter.cpp

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "PubSubParticipant.hpp"
4242
#include "PubSubReader.hpp"
4343
#include "PubSubWriter.hpp"
44+
#include <fastdds/dds/builtin/topic/PublicationBuiltinTopicData.hpp>
45+
#include <fastdds/rtps/writer/WriterDiscoveryStatus.hpp>
4446

4547
using namespace eprosima::fastdds;
4648

@@ -1879,35 +1881,100 @@ TEST(DDSDataWriter, transport_priority_mutable)
18791881

18801882
// ----------- Procedure -----------
18811883

1882-
// 1. Create a disabled `DataWriter` with default QoS.
1884+
// 1. Create a participant with a custom listener that captures the transport priority
1885+
// of the discovered writer.
1886+
struct CustomListener : public fdds::DomainParticipantListener
1887+
{
1888+
void on_data_writer_discovery(
1889+
fdds::DomainParticipant* /* participant */,
1890+
rtps::WriterDiscoveryStatus reason,
1891+
const fdds::PublicationBuiltinTopicData& info,
1892+
bool& should_be_ignored) override
1893+
{
1894+
std::lock_guard<std::mutex> lock(mtx_);
1895+
1896+
if (reason == rtps::WriterDiscoveryStatus::DISCOVERED_WRITER)
1897+
{
1898+
// Capture the transport priority of the discovered writer.
1899+
ASSERT_TRUE(info.transport_priority.has_value());
1900+
discovered_transport_priority_ = info.transport_priority->value;
1901+
}
1902+
else if (reason == rtps::WriterDiscoveryStatus::CHANGED_QOS_WRITER)
1903+
{
1904+
// Capture the updated transport priority of the writer.
1905+
ASSERT_TRUE(info.transport_priority.has_value());
1906+
updated_transport_priority_ = info.transport_priority->value;
1907+
cv_.notify_all();
1908+
}
1909+
1910+
should_be_ignored = false;
1911+
}
1912+
1913+
void wait_update()
1914+
{
1915+
std::unique_lock<std::mutex> lock(mtx_);
1916+
// Wait for the transport priority to be updated.
1917+
cv_.wait(lock, [this]
1918+
{
1919+
return updated_transport_priority_ != 0;
1920+
});
1921+
}
1922+
1923+
void check_expectations() const
1924+
{
1925+
std::lock_guard<std::mutex> lock(mtx_);
1926+
int32_t prio = PRIORITY_2;
1927+
EXPECT_EQ(discovered_transport_priority_, prio);
1928+
prio = PRIORITY_3;
1929+
EXPECT_EQ(updated_transport_priority_, prio);
1930+
}
1931+
1932+
private:
1933+
1934+
mutable std::mutex mtx_;
1935+
std::condition_variable cv_;
1936+
int32_t discovered_transport_priority_ = 0;
1937+
int32_t updated_transport_priority_ = 0;
1938+
};
1939+
1940+
CustomListener custom_listener;
1941+
auto factory = fdds::DomainParticipantFactory::get_shared_instance();
1942+
fdds::DomainId_t domain_id = static_cast<fdds::DomainId_t>(GET_PID()) % 230;
1943+
fdds::DomainParticipant* participant = factory->create_participant(
1944+
domain_id, fdds::PARTICIPANT_QOS_DEFAULT, &custom_listener, fdds::StatusMask::none());
1945+
1946+
// 2. Create a disabled `DataWriter` with default QoS.
18831947
fdds::PublisherQos pub_qos{};
18841948
pub_qos.entity_factory().autoenable_created_entities = false;
18851949
writer.publisher_qos(pub_qos).init();
18861950
fdds::DataWriter& data_writer = writer.get_native_writer();
18871951

1888-
// 2. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_1`.
1952+
// 3. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_1`.
18891953
auto current_qos = data_writer.get_qos();
18901954
int32_t transport_priority_1 = current_qos.transport_priority().value;
18911955

1892-
// 3. Update the transport priority in `current_qos` to `PRIORITY_2` and set the `DataWriter` QoS to `current_qos`.
1956+
// 4. Update the transport priority in `current_qos` to `PRIORITY_2` and set the `DataWriter` QoS to `current_qos`.
18931957
current_qos.transport_priority().value = PRIORITY_2;
18941958
EXPECT_EQ(data_writer.set_qos(current_qos), fdds::RETCODE_OK);
18951959

1896-
// 4. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_2`.
1960+
// 5. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_2`.
18971961
current_qos = data_writer.get_qos();
18981962
int32_t transport_priority_2 = current_qos.transport_priority().value;
18991963

1900-
// 5. Enable the `DataWriter`.
1964+
// 6. Enable the `DataWriter`.
19011965
EXPECT_EQ(data_writer.enable(), fdds::RETCODE_OK);
19021966

1903-
// 6. Update the transport priority in `current_qos` to `PRIORITY_3` and set the `DataWriter` QoS to `current_qos`.
1967+
// 7. Update the transport priority in `current_qos` to `PRIORITY_3` and set the `DataWriter` QoS to `current_qos`.
19041968
current_qos.transport_priority().value = PRIORITY_3;
19051969
EXPECT_EQ(data_writer.set_qos(current_qos), fdds::RETCODE_OK);
19061970

1907-
// 7. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_3`.
1971+
// 8. Get the writer's current QoS into `current_qos` and save the transport priority into `transport_priority_3`.
19081972
current_qos = data_writer.get_qos();
19091973
int32_t transport_priority_3 = current_qos.transport_priority().value;
19101974

1975+
// 9. Wait for the participant to discover the `DataWriter` and update the transport priority.
1976+
custom_listener.wait_update();
1977+
19111978
// ----------- Assertions -----------
19121979

19131980
// 1. `transport_priority_1` equals `0`.
@@ -1918,6 +1985,14 @@ TEST(DDSDataWriter, transport_priority_mutable)
19181985

19191986
// 3. `transport_priority_3` equals `PRIORITY_3`.
19201987
EXPECT_EQ(transport_priority_3, PRIORITY_3);
1988+
1989+
// 4. The other participant discovered and updated transport priorities
1990+
// are equal to `PRIORITY_2` and `PRIORITY_3`, respectively.
1991+
custom_listener.check_expectations();
1992+
1993+
// ----------- Cleanup -----------
1994+
1995+
factory->delete_participant(participant);
19211996
}
19221997

19231998
/**

0 commit comments

Comments
 (0)