feat(ha): add phase2_done, repl_ack_count, n_peers, client_ssl_ctx fields and CTRL_PRIMARY_COMMITTING enum
Task 2.1 of election-iomgr-refactor spec. Adds the new ha_state_t fields required for the COMMITTING phase FSM, the CTRL_PRIMARY_COMMITTING role enum value, and the committing_timeout_ms config field with its default constant. ha_init() explicitly zero-initialises all new fields. Unit test verifies zero-init and enum distinctness. Requirements: 5.2, 8.1 (election-iomgr-refactor spec)
This commit is contained in:
parent
c3caab49a6
commit
e42564b3bd
3 changed files with 79 additions and 14 deletions
|
|
@ -321,6 +321,54 @@ void test_am_i_primary_p1_deadline_expires(void)
|
|||
printf("test_am_i_primary_p1_deadline_expires: PASS\n");
|
||||
}
|
||||
|
||||
/* ── Task 2.1: ha_state_t new fields zero-initialised by ha_init ──────── */
|
||||
|
||||
/*
|
||||
* Verify that ha_init zeroes the new fields added for election-iomgr-refactor:
|
||||
* phase2_done, repl_ack_count, n_peers, client_ssl_ctx
|
||||
* and that CTRL_PRIMARY_COMMITTING is a distinct enum value in ctrl_role_t.
|
||||
* Also verifies ha_config_t.committing_timeout_ms default macro exists.
|
||||
*
|
||||
* Requirements: 5.2, 8.1 (election-iomgr-refactor spec)
|
||||
*/
|
||||
static void test_ha_init_zeroes_new_fields(void)
|
||||
{
|
||||
ha_state_t ha;
|
||||
ha_config_t cfg = {
|
||||
.heartbeat_interval_ms = 3000,
|
||||
.heartbeat_timeout_ms = 10000,
|
||||
.election_timeout_ms = 2000,
|
||||
.probe_connect_timeout_ms = 500,
|
||||
.max_promotion_retries = 5,
|
||||
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
|
||||
};
|
||||
TEST_ASSERT_EQUAL_INT(0, ha_init(&ha, &cfg, 0));
|
||||
|
||||
/* phase2_done must be explicitly zero after ha_init */
|
||||
TEST_ASSERT_EQUAL_INT(0, ha.phase2_done);
|
||||
|
||||
/* repl_ack_count is _Atomic int; must be zero after ha_init */
|
||||
TEST_ASSERT_EQUAL_INT(0, atomic_load_explicit(&ha.repl_ack_count, memory_order_relaxed));
|
||||
|
||||
/* n_peers must be zero after ha_init */
|
||||
TEST_ASSERT_EQUAL_INT(0, ha.n_peers);
|
||||
|
||||
/* client_ssl_ctx must be NULL after ha_init */
|
||||
TEST_ASSERT_NULL(ha.client_ssl_ctx);
|
||||
|
||||
/* committing_timeout_ms stored in config */
|
||||
TEST_ASSERT_EQUAL_UINT32(HA_DEFAULT_COMMITTING_TIMEOUT_MS, ha.config.committing_timeout_ms);
|
||||
|
||||
/* CTRL_PRIMARY_COMMITTING must be a distinct enum value */
|
||||
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY_COMMITTING, (int)CTRL_PRIMARY);
|
||||
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY_COMMITTING, (int)CTRL_STANDBY);
|
||||
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY_COMMITTING, (int)CTRL_INIT);
|
||||
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY_COMMITTING, (int)CTRL_ELECTING);
|
||||
|
||||
ha_fini(&ha);
|
||||
printf("test_ha_init_zeroes_new_fields: PASS\n");
|
||||
}
|
||||
|
||||
void test_ha_role(void)
|
||||
{
|
||||
RUN_TEST(test_ha_init_default_role_is_standby);
|
||||
|
|
@ -335,6 +383,8 @@ void test_ha_role(void)
|
|||
RUN_TEST(test_promote_increments_term);
|
||||
RUN_TEST(test_demote_sets_standby_role);
|
||||
RUN_TEST(test_sigusr1_sets_failover_requested);
|
||||
/* Task 2.1: election-iomgr-refactor new fields */
|
||||
RUN_TEST(test_ha_init_zeroes_new_fields);
|
||||
}
|
||||
|
||||
/* ── P1-6 suite: am_i_primary() election ─────────────────────────────── */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue