Skip to content

Commit f0cd0d7

Browse files
mergify[bot]MiguelCompanyjuanlofer-eprosima
authored
Send heartbeat when wait_for_all_acked is called (#6098) (#6103)
* 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) * Uncrustify Signed-off-by: Juan Lopez Fernandez <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> Signed-off-by: Juan Lopez Fernandez <[email protected]> Co-authored-by: Miguel Company <[email protected]> Co-authored-by: Juan Lopez Fernandez <[email protected]>
1 parent 5541701 commit f0cd0d7

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/cpp/rtps/writer/StatefulWriter.cpp

Lines changed: 6 additions & 2 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

@@ -1508,7 +1510,8 @@ void StatefulWriter::check_acked_status()
15081510
listener_->on_writer_change_received_by_all(this, change);
15091511

15101512
// Stop if we got to either next_all_acked_notify_sequence_ or the first change
1511-
} while (seq > end_seq);
1513+
}
1514+
while (seq > end_seq);
15121515
}
15131516

15141517
next_all_acked_notify_sequence_ = min_low_mark + 1;
@@ -2079,7 +2082,8 @@ bool StatefulWriter::ack_timer_expired()
20792082
do
20802083
{
20812084
last_sequence_number_++;
2082-
} while (!history_->get_change(
2085+
}
2086+
while (!history_->get_change(
20832087
last_sequence_number_,
20842088
getGuid(),
20852089
&change) && last_sequence_number_ < next_sequence_number());

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)