feat(ha-repl-hardening): add per-standby convergence tracking arrays (task 1.4)
Add standby_reported_tag/lsn/converged arrays to ha_state_t, sized MAX_HA_CANDIDATES. Zero-init via existing memset in ha_init(). Unit test verifies zero-init and writability.
This commit is contained in:
parent
0121bc0683
commit
e3ca775f0d
4 changed files with 55 additions and 1 deletions
|
|
@ -194,6 +194,49 @@ static void test_ha_init_zeroes_new_fields(void)
|
|||
printf("test_ha_init_zeroes_new_fields: PASS\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Task 1.4: per-standby convergence tracking fields zero-initialised by ha_init.
|
||||
*
|
||||
* Verifies:
|
||||
* - standby_reported_tag[i] == 0 for all i after ha_init()
|
||||
* - standby_reported_lsn[i] == 0 for all i after ha_init()
|
||||
* - standby_converged[i] == false for all i after ha_init()
|
||||
* - fields are writable from test context
|
||||
*
|
||||
* Requirements: 2.1 (ha-repl-hardening spec)
|
||||
*/
|
||||
static void test_ha_init_zeroes_standby_convergence_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));
|
||||
|
||||
/* All per-standby tracking arrays must be zero/false after ha_init */
|
||||
for (int i = 0; i < MAX_HA_CANDIDATES; i++) {
|
||||
TEST_ASSERT_EQUAL_UINT64(0, ha.standby_reported_tag[i]);
|
||||
TEST_ASSERT_EQUAL_UINT64(0, ha.standby_reported_lsn[i]);
|
||||
TEST_ASSERT_FALSE(ha.standby_converged[i]);
|
||||
}
|
||||
|
||||
/* Fields must be writable */
|
||||
ha.standby_reported_tag[0] = 42ULL;
|
||||
ha.standby_reported_lsn[0] = 100ULL;
|
||||
ha.standby_converged[0] = true;
|
||||
TEST_ASSERT_EQUAL_UINT64(42ULL, ha.standby_reported_tag[0]);
|
||||
TEST_ASSERT_EQUAL_UINT64(100ULL, ha.standby_reported_lsn[0]);
|
||||
TEST_ASSERT_TRUE(ha.standby_converged[0]);
|
||||
|
||||
ha_fini(&ha);
|
||||
printf("test_ha_init_zeroes_standby_convergence_fields: PASS\n");
|
||||
}
|
||||
|
||||
void test_ha_role(void)
|
||||
{
|
||||
RUN_TEST(test_ha_init_default_role_is_standby);
|
||||
|
|
@ -207,6 +250,8 @@ void test_ha_role(void)
|
|||
/* Watchdog / SIGUSR1 tests deleted */
|
||||
/* Task 2.1: election-iomgr-refactor new fields */
|
||||
RUN_TEST(test_ha_init_zeroes_new_fields);
|
||||
/* Task 1.4: ha-repl-hardening per-standby convergence fields */
|
||||
RUN_TEST(test_ha_init_zeroes_standby_convergence_fields);
|
||||
}
|
||||
|
||||
/* test_am_i_primary suite deleted — am_i_primary() removed (election-iomgr-refactor) */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue