Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Nov 24, 2023
1 parent 569650e commit b0dc715
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/test_raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ void test_apply_time_change_result(void**) {
assert_true(raft->GetLastTime() == n);
}

void test_follower_to_candidate_on_timeout(void**) {
auto ts = std::make_shared<TFakeTimeSource>();
auto raft = MakeRaft({}, 3, ts);
assert_true(raft->CurrentStateName() == EState::FOLLOWER);
raft->Process(NewTimeout());
assert_true(raft->CurrentStateName() == EState::FOLLOWER);
ts->Advance(std::chrono::milliseconds(10000));
raft->Process(NewTimeout());
assert_true(raft->CurrentStateName() == EState::CANDIDATE);
}

int main() {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_empty),
Expand All @@ -212,6 +223,7 @@ int main() {
cmocka_unit_test(test_apply_empty_result),
cmocka_unit_test(test_apply_state_func_change_result),
cmocka_unit_test(test_apply_time_change_result),
cmocka_unit_test(test_follower_to_candidate_on_timeout),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}

0 comments on commit b0dc715

Please sign in to comment.