Skip to content

Commit 57ae3c1

Browse files
MiguelCompanymergify[bot]
authored andcommitted
Send heartbeat when wait_for_all_acked is called (#6098)
* Refs #23798. Add test. Signed-off-by: Miguel Company <[email protected]> * Refs #23798. Send heartbeat when wait_for_all_acked is called. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> (cherry picked from commit db8f527)
1 parent 34f95aa commit 57ae3c1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/cpp/rtps/writer/StatefulWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,8 @@ bool StatefulWriter::all_readers_updated()
13871387
bool StatefulWriter::wait_for_all_acked(
13881388
const dds::Duration_t& max_wait)
13891389
{
1390+
send_periodic_heartbeat();
1391+
13901392
std::unique_lock<RecursiveTimedMutex> lock(mp_mutex);
13911393
std::unique_lock<std::mutex> all_acked_lock(all_acked_mutex_);
13921394

test/blackbox/common/BlackboxTestsReliability.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,45 @@ TEST(Reliability, DisableHeartbeatPiggybackTrue)
100100
{
101101
reliability_disable_heartbeat_piggyback(true);
102102
}
103+
104+
/**
105+
* This test checks that waitForAllAcked() triggers a heartbeat if needed.
106+
*/
107+
TEST(Reliability, wait_for_all_acked_triggers_heartbeat)
108+
{
109+
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
110+
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
111+
112+
// Either ensure that the history will not become full, or disable piggyback heartbeats
113+
static constexpr int32_t HISTORY_DEPTH = 10;
114+
static constexpr int32_t NUM_SAMPLES = 1;
115+
static_assert(NUM_SAMPLES < HISTORY_DEPTH, "NUM_SAMPLES must be less than HISTORY_DEPTH");
116+
117+
reader.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
118+
.history_kind(eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS)
119+
.history_depth(HISTORY_DEPTH)
120+
.init();
121+
122+
writer.reliability(eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS)
123+
.history_kind(eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS)
124+
.history_depth(HISTORY_DEPTH)
125+
.heartbeat_period_seconds(180000) // Large heartbeat period to avoid interference
126+
.init();
127+
128+
ASSERT_TRUE(reader.isInitialized());
129+
ASSERT_TRUE(writer.isInitialized());
130+
131+
// Wait for discovery.
132+
writer.wait_discovery();
133+
reader.wait_discovery();
134+
135+
// Wait for the initial heartbeat/acknack exchange to finish
136+
std::this_thread::sleep_for(std::chrono::seconds(1));
137+
138+
auto data = default_helloworld_data_generator(NUM_SAMPLES);
139+
writer.send(data);
140+
ASSERT_TRUE(data.empty());
141+
142+
// Wait until all data is acknowledged. This should trigger a heartbeat.
143+
ASSERT_TRUE(writer.waitForAllAcked(std::chrono::seconds(1)));
144+
}

0 commit comments

Comments
 (0)