From 717a5fafa5fcbee87c579c2c1bdbb0ffa7e178fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ma=C5=9Blanka?= Date: Tue, 17 Dec 2024 11:52:25 +0100 Subject: [PATCH] r/tests: added test checking if leadership is stable after timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Maślanka --- src/v/raft/tests/basic_raft_fixture_test.cc | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/v/raft/tests/basic_raft_fixture_test.cc b/src/v/raft/tests/basic_raft_fixture_test.cc index 2050b11ce068..f26468a55176 100644 --- a/src/v/raft/tests/basic_raft_fixture_test.cc +++ b/src/v/raft/tests/basic_raft_fixture_test.cc @@ -836,3 +836,29 @@ TEST_F_CORO(raft_fixture, leadership_transfer_delay) { ASSERT_LE_CORO(election_time * 1.0, transfer_time * tolerance_multiplier); ASSERT_GE_CORO(election_time * 1.0, transfer_time / tolerance_multiplier); } + +TEST_F_CORO(raft_fixture, test_no_stepdown_on_append_entries_timeout) { + config::shard_local_cfg().replicate_append_timeout_ms.set_value(1s); + co_await create_simple_group(3); + auto leader_id = co_await wait_for_leader(10s); + for (auto& [id, n] : nodes()) { + if (id != leader_id) { + n->f_injectable_log()->set_append_delay([]() { return 5s; }); + } + } + + auto& leader_node = node(leader_id); + auto term_before = leader_node.raft()->term(); + auto r = co_await leader_node.raft()->replicate( + make_batches(1, 10, 128), + replicate_options(consistency_level::quorum_ack, 10s)); + ASSERT_FALSE_CORO(r.has_error()); + for (auto& [_, n] : nodes()) { + n->f_injectable_log()->set_append_delay(std::nullopt); + } + + leader_id = co_await wait_for_leader(10s); + auto& new_leader_node = node(leader_id); + ASSERT_EQ_CORO(term_before, new_leader_node.raft()->term()); + ASSERT_TRUE_CORO(new_leader_node.raft()->is_leader()); +}