|
14 | 14 |
|
15 | 15 | #include "BlackboxTests.hpp"
|
16 | 16 |
|
| 17 | +#include <string> |
17 | 18 | #include <thread>
|
18 | 19 |
|
19 | 20 | #include "PubSubReader.hpp"
|
@@ -2039,6 +2040,175 @@ TEST(LivelinessTests, correct_liveliness_state_one_writer_multiple_readers)
|
2039 | 2040 | ASSERT_EQ(reader.sub_wait_liveliness_lost_for(2, std::chrono::seconds(4)), 2u);
|
2040 | 2041 | }
|
2041 | 2042 |
|
| 2043 | +/** |
| 2044 | + * This is a regression test for redmine issue #21189. |
| 2045 | + * |
| 2046 | + * The test ensures that liveliness changed status is not affected by writers on a topic different from |
| 2047 | + * the one of the reader. |
| 2048 | + * |
| 2049 | + * The test creates two readers and two writers, each reader and writer pair on a different topic. |
| 2050 | + * Writing a sample on one writer should not affect the liveliness changed status of the other reader. |
| 2051 | + * Destroying the writer should not affect the liveliness changed status of the other reader. |
| 2052 | + */ |
| 2053 | +static void test_liveliness_qos_independent_topics( |
| 2054 | + const std::string& topic_name, |
| 2055 | + eprosima::fastdds::dds::ReliabilityQosPolicyKind reliability_kind) |
| 2056 | +{ |
| 2057 | + const auto lease_dutation_time = std::chrono::seconds(1); |
| 2058 | + const eprosima::fastrtps::Duration_t lease_duration(1, 0); |
| 2059 | + const eprosima::fastrtps::Duration_t announcement_period(0, 250000000); |
| 2060 | + |
| 2061 | + PubSubReader<HelloWorldPubSubType> reader1(topic_name + "1"); |
| 2062 | + PubSubReader<HelloWorldPubSubType> reader2(topic_name + "2"); |
| 2063 | + |
| 2064 | + PubSubWriter<HelloWorldPubSubType> writer1(topic_name + "1"); |
| 2065 | + PubSubWriter<HelloWorldPubSubType> writer2(topic_name + "2"); |
| 2066 | + |
| 2067 | + // Configure and start the readers |
| 2068 | + reader1.liveliness_kind(eprosima::fastdds::dds::AUTOMATIC_LIVELINESS_QOS) |
| 2069 | + .liveliness_lease_duration(lease_duration) |
| 2070 | + .reliability(reliability_kind) |
| 2071 | + .init(); |
| 2072 | + reader2.liveliness_kind(eprosima::fastdds::dds::AUTOMATIC_LIVELINESS_QOS) |
| 2073 | + .liveliness_lease_duration(lease_duration) |
| 2074 | + .reliability(reliability_kind) |
| 2075 | + .init(); |
| 2076 | + |
| 2077 | + // Configure and start the writers |
| 2078 | + writer1.liveliness_kind(eprosima::fastdds::dds::AUTOMATIC_LIVELINESS_QOS) |
| 2079 | + .liveliness_lease_duration(lease_duration) |
| 2080 | + .liveliness_announcement_period(announcement_period) |
| 2081 | + .reliability(reliability_kind) |
| 2082 | + .init(); |
| 2083 | + writer2.liveliness_kind(eprosima::fastdds::dds::AUTOMATIC_LIVELINESS_QOS) |
| 2084 | + .liveliness_lease_duration(lease_duration) |
| 2085 | + .liveliness_announcement_period(announcement_period) |
| 2086 | + .reliability(reliability_kind) |
| 2087 | + .init(); |
| 2088 | + |
| 2089 | + // Wait for discovery |
| 2090 | + reader1.wait_discovery(); |
| 2091 | + reader2.wait_discovery(); |
| 2092 | + writer1.wait_discovery(); |
| 2093 | + writer2.wait_discovery(); |
| 2094 | + |
| 2095 | + HelloWorldPubSubType::type data; |
| 2096 | + |
| 2097 | + // Write a sample on writer1 and wait for reader1 to assert writer1's liveliness |
| 2098 | + writer1.send_sample(data); |
| 2099 | + reader1.wait_liveliness_recovered(); |
| 2100 | + |
| 2101 | + // Check liveliness changed status on both readers |
| 2102 | + { |
| 2103 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2104 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2105 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2106 | + } |
| 2107 | + |
| 2108 | + { |
| 2109 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2110 | + EXPECT_EQ(liveliness.alive_count, 0); |
| 2111 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2112 | + } |
| 2113 | + |
| 2114 | + // Write a sample on writer2 and wait for reader2 to assert writer2's liveliness |
| 2115 | + writer2.send_sample(data); |
| 2116 | + reader2.wait_liveliness_recovered(); |
| 2117 | + |
| 2118 | + // Check liveliness changed status on both readers |
| 2119 | + { |
| 2120 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2121 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2122 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2123 | + } |
| 2124 | + |
| 2125 | + { |
| 2126 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2127 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2128 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2129 | + } |
| 2130 | + |
| 2131 | + // Destroy writer2 and wait twice the lease duration time |
| 2132 | + writer2.destroy(); |
| 2133 | + std::this_thread::sleep_for(lease_dutation_time * 2); |
| 2134 | + |
| 2135 | + // Check liveliness changed status on both readers |
| 2136 | + { |
| 2137 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2138 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2139 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2140 | + } |
| 2141 | + |
| 2142 | + { |
| 2143 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2144 | + EXPECT_EQ(liveliness.alive_count, 0); |
| 2145 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2146 | + } |
| 2147 | + |
| 2148 | + // Start writer2 again and wait for reader2 to assert writer2's liveliness |
| 2149 | + writer2.init(); |
| 2150 | + reader2.wait_discovery(); |
| 2151 | + writer2.send_sample(data); |
| 2152 | + reader2.wait_liveliness_recovered(2); |
| 2153 | + |
| 2154 | + // Check liveliness changed status on both readers |
| 2155 | + { |
| 2156 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2157 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2158 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2159 | + } |
| 2160 | + |
| 2161 | + { |
| 2162 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2163 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2164 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2165 | + } |
| 2166 | + |
| 2167 | + // Destroy writer1 and wait twice the lease duration time |
| 2168 | + writer1.destroy(); |
| 2169 | + std::this_thread::sleep_for(lease_dutation_time * 2); |
| 2170 | + |
| 2171 | + // Check liveliness changed status on both readers |
| 2172 | + { |
| 2173 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2174 | + EXPECT_EQ(liveliness.alive_count, 0); |
| 2175 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2176 | + } |
| 2177 | + |
| 2178 | + { |
| 2179 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2180 | + EXPECT_EQ(liveliness.alive_count, 1); |
| 2181 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2182 | + } |
| 2183 | + |
| 2184 | + // Destroy writer2 and wait twice the lease duration time |
| 2185 | + writer2.destroy(); |
| 2186 | + std::this_thread::sleep_for(lease_dutation_time * 2); |
| 2187 | + |
| 2188 | + // Check liveliness changed status on both readers |
| 2189 | + { |
| 2190 | + auto liveliness = reader1.liveliness_changed_status(); |
| 2191 | + EXPECT_EQ(liveliness.alive_count, 0); |
| 2192 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2193 | + } |
| 2194 | + |
| 2195 | + { |
| 2196 | + auto liveliness = reader2.liveliness_changed_status(); |
| 2197 | + EXPECT_EQ(liveliness.alive_count, 0); |
| 2198 | + EXPECT_EQ(liveliness.not_alive_count, 0); |
| 2199 | + } |
| 2200 | +} |
| 2201 | + |
| 2202 | +TEST_P(LivelinessQos, IndependentTopics_reliable) |
| 2203 | +{ |
| 2204 | + test_liveliness_qos_independent_topics(TEST_TOPIC_NAME, eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS); |
| 2205 | +} |
| 2206 | + |
| 2207 | +TEST_P(LivelinessQos, IndependentTopics_besteffort) |
| 2208 | +{ |
| 2209 | + test_liveliness_qos_independent_topics(TEST_TOPIC_NAME, eprosima::fastdds::dds::BEST_EFFORT_RELIABILITY_QOS); |
| 2210 | +} |
| 2211 | + |
2042 | 2212 | #ifdef INSTANTIATE_TEST_SUITE_P
|
2043 | 2213 | #define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
|
2044 | 2214 | #else
|
|
0 commit comments