test(ha-single-leader-role): sweep all COMMITTING fixtures to direct-PRIMARY contract (task 5.1)

This commit is contained in:
Rongsong Shen 2026-06-13 13:59:42 +00:00
parent 71ce41f486
commit 7f974e766b
11 changed files with 138 additions and 169 deletions

View file

@ -151,10 +151,10 @@ static void test_demote_sets_standby_role(void)
/*
* 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.
* and that the surviving leader role values are distinct in ctrl_role_t.
*
* Requirements: 5.2, 8.1 (election-iomgr-refactor spec)
* Requirements: 5.2, 8.1 (election-iomgr-refactor spec); 1.2 (ha-single-leader-role:
* single leader role — no transitional leader state observable)
*/
static void test_ha_init_zeroes_new_fields(void)
{
@ -165,7 +165,6 @@ static void test_ha_init_zeroes_new_fields(void)
.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));
@ -181,14 +180,11 @@ static void test_ha_init_zeroes_new_fields(void)
/* 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);
/* The four surviving roles are distinct: the single leader role is
* CTRL_PRIMARY (no transitional leader sub-state, Req 1.2). */
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY, (int)CTRL_STANDBY);
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY, (int)CTRL_INIT);
TEST_ASSERT_NOT_EQUAL((int)CTRL_PRIMARY, (int)CTRL_ELECTING);
ha_fini(&ha);
printf("test_ha_init_zeroes_new_fields: PASS\n");
@ -214,7 +210,6 @@ static void test_ha_init_zeroes_standby_convergence_fields(void)
.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));
@ -259,7 +254,6 @@ static ha_state_t *build_ha_for_convergence_test(void)
.election_timeout_ms = 2000,
.probe_connect_timeout_ms = 500,
.max_promotion_retries = 5,
.committing_timeout_ms = HA_DEFAULT_COMMITTING_TIMEOUT_MS,
};
ha_init(&ha, &cfg, 0);
return &ha;
@ -669,28 +663,9 @@ static void test_evaluate_repl_action_stream_wal_fresh_system(void)
printf("test_evaluate_repl_action_stream_wal_fresh_system: PASS\n");
}
/* ── Task 5.3: committing timeout default value ──────────────────────────────
*
* Requirements: 6.4 (ha-repl-hardening)
*
* The committing_timeout_ms CONFIG knob survives until task 5.2 (it is a
* different token from the deleted committing-timeout watchdog callback). The
* degraded-mode force-promotion cases that drove the watchdog test wrapper
* were machinery-subject and were deleted (ha-single-leader-role task 4.1,
* design §"Transitional-State Deletions": no shims). Only the config-default
* assertion remains.
*/
/*
* Test: HA_DEFAULT_COMMITTING_TIMEOUT_MS is 60000 (not 10000).
* Requirements: 6.4 (ha-repl-hardening) — "Change committing_timeout_ms default from 10000 to 60000"
*/
static void test_committing_timeout_default_is_60s(void)
{
TEST_ASSERT_EQUAL_UINT32_MESSAGE(60000, HA_DEFAULT_COMMITTING_TIMEOUT_MS,
"HA_DEFAULT_COMMITTING_TIMEOUT_MS must be 60000 (Req 6.4, Task 5.3)");
printf("test_committing_timeout_default_is_60s: PASS\n");
}
/* The transitional-leader timeout default test was removed: the config knob
* and its default macro are deleted by ha-single-leader-role (the wall-clock
* force-promotion watchdog it configured is gone — Req 1.5). */
/* ── Task 3.3 (ha-wal-replication): dispatch gate allows OPCode_walCatchupEntry
* in CTRL_STANDBY, CTRL_ELECTING, and CTRL_INIT.
@ -698,8 +673,8 @@ static void test_committing_timeout_default_is_60s(void)
* Requirements: ha-wal-replication Req 3.3 (standby role guard).
* Verifies that ha_dispatch_gate(ha, OPCode_walCatchupEntry) returns 0
* (allow) for the three roles where a standby legitimately receives WAL
* catch-up entries from the primary. CTRL_PRIMARY and
* CTRL_PRIMARY_COMMITTING must NOT allow it (they never receive WAL pushes). */
* catch-up entries from the primary. CTRL_PRIMARY must NOT allow it
* (the leader never receives WAL pushes). */
static void test_dispatch_gate_allows_wal_catchup_in_standby_roles(void)
{
ha_state_t ha;
@ -709,7 +684,6 @@ static void test_dispatch_gate_allows_wal_catchup_in_standby_roles(void)
.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));
@ -771,10 +745,8 @@ void test_ha_role(void)
RUN_TEST(test_dispatch_repl_action_send_snapshot);
/* Task 5.2 convergence-checker cases deleted (ha-single-leader-role 4.1:
* the majority-convergence checker removed — no shims, machinery-subject) */
/* Task 5.3: committing timeout config-default knob (committing_timeout_ms
* survives until task 5.2; the degraded-mode committing-timeout watchdog
* cases were deleted — ha-single-leader-role 4.1, machinery-subject) */
RUN_TEST(test_committing_timeout_default_is_60s);
/* transitional-leader timeout default test removed (ha-single-leader-role:
* config knob + wall-clock watchdog deleted, Req 1.5) */
/* Task 3.3 (ha-wal-replication): dispatch gate standby-role guard */
RUN_TEST(test_dispatch_gate_allows_wal_catchup_in_standby_roles);
}