Skip to content

Commit

Permalink
r/tests: always use current leader offsets in linearizable barrier test
Browse files Browse the repository at this point in the history
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 <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Sep 5, 2023
1 parent 64d58c6 commit 8e906cc
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/v/raft/tests/append_entries_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <system_error>
Expand Down Expand Up @@ -747,18 +748,28 @@ FIXTURE_TEST(test_linarizable_barrier, raft_test_fixture) {
BOOST_REQUIRE(success);
leader_raft = gr.get_member(leader_id).consensus;
result<model::offset> r(raft::errc::timeout);
retry_with_leader(gr, 5, 30s, [&r](raft_node& leader_node) {
return leader_node.consensus->linearizable_barrier().then(
[&r](result<model::offset> 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<model::offset> 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) {
Expand Down

0 comments on commit 8e906cc

Please sign in to comment.