Skip to content

Commit

Permalink
rm_stm/tests: add test for producer expiration without data batches
Browse files Browse the repository at this point in the history
In earlier versions we were not considering transactions without data
batches as candidates for expiry, thats not the case any more with
redpanda-data#18076, adding a
regression test to future proof.
  • Loading branch information
bharathv authored and Lazin committed Jun 11, 2024
1 parent bcc9b49 commit 2771e66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/v/cluster/tests/rm_stm_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct rm_stm_test_fixture : simple_raft_fixture {
return _stm->wait(raft_offset, model::timeout_clock::now() + 10ms);
}

auto get_expired_producers() const { return _stm->get_expired_producers(); }

ss::sharded<cluster::tx_gateway_frontend> tx_gateway_frontend;
ss::sharded<cluster::producer_state_manager> producer_state_manager;
ss::shared_ptr<cluster::rm_stm> _stm;
Expand Down
25 changes: 25 additions & 0 deletions src/v/cluster/tests/rm_stm_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,28 @@ FIXTURE_TEST(test_snapshot_v3_v4_v5_equivalence, rm_stm_test_fixture) {
highest_pid_from_snapshot, _stm->highest_producer_id());
}
}

FIXTURE_TEST(test_tx_expiration_without_data_batches, rm_stm_test_fixture) {
create_stm_and_start_raft();
auto& stm = *_stm;
stm.start().get0();
stm.testing_only_disable_auto_abort();

wait_for_confirmed_leader();
wait_for_meta_initialized();
// Add a fence batch
auto pid = model::producer_identity{0, 0};
auto term_op = stm
.begin_tx(
pid,
model::tx_seq{0},
std::chrono::milliseconds(10),
model::partition_id(0))
.get0();
BOOST_REQUIRE(term_op.has_value());
BOOST_REQUIRE_EQUAL(term_op.value(), _raft->confirmed_term());
tests::cooperative_spin_wait_with_timeout(5s, [this, pid]() {
auto expired = get_expired_producers();
return std::find(expired.begin(), expired.end(), pid) != expired.end();
}).get0();
}

0 comments on commit 2771e66

Please sign in to comment.