From 8e906cccabbc0fc10af8c8c25b8093943aedfd20 Mon Sep 17 00:00:00 2001 From: Michal Maslanka Date: Tue, 5 Sep 2023 09:32:07 +0200 Subject: [PATCH] r/tests: always use current leader offsets in linearizable barrier test Previously the linearizable barrier test might use out of date leader offsets to assert if the barrier was executed correctly. This made the test flaky especially for slow debug builds where leadership can change throughout the test. Signed-off-by: Michal Maslanka --- src/v/raft/tests/append_entries_test.cc | 31 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/v/raft/tests/append_entries_test.cc b/src/v/raft/tests/append_entries_test.cc index 13e9ba497bfe7..960b3e2f8b17a 100644 --- a/src/v/raft/tests/append_entries_test.cc +++ b/src/v/raft/tests/append_entries_test.cc @@ -24,6 +24,7 @@ #include "storage/kvstore.h" #include "storage/record_batch_builder.h" #include "storage/tests/utils/disk_log_builder.h" +#include "storage/types.h" #include "test_utils/async.h" #include @@ -747,18 +748,28 @@ FIXTURE_TEST(test_linarizable_barrier, raft_test_fixture) { BOOST_REQUIRE(success); leader_raft = gr.get_member(leader_id).consensus; result r(raft::errc::timeout); - retry_with_leader(gr, 5, 30s, [&r](raft_node& leader_node) { - return leader_node.consensus->linearizable_barrier().then( - [&r](result l_offset) { - r = l_offset; - return l_offset.has_value(); - }); - }).get(); - + auto leader_offsets = leader_raft->log()->offsets(); + retry_with_leader( + gr, + 5, + 30s, + [&r, &leader_offsets](raft_node& leader_node) { + return leader_node.consensus->linearizable_barrier().then( + [&r, &leader_offsets, &leader_node]( + result l_offset) { + r = l_offset; + leader_offsets = leader_node.log->offsets(); + return l_offset.has_value(); + }); + }) + .get(); + // query leader again as leadership may changed + leader_id = wait_for_group_leader(gr); + leader_raft = gr.get_member(leader_id).consensus; // linerizable barrier must succeed with stable leader BOOST_REQUIRE(r.has_value()); - BOOST_REQUIRE_EQUAL(r.value(), leader_raft->committed_offset()); - BOOST_REQUIRE_EQUAL(r.value(), leader_raft->dirty_offset()); + BOOST_REQUIRE_EQUAL(r.value(), leader_offsets.committed_offset); + BOOST_REQUIRE_EQUAL(r.value(), leader_offsets.dirty_offset); }; FIXTURE_TEST(test_linarizable_barrier_single_node, raft_test_fixture) {