test(ha-single-leader-role): sweep all COMMITTING fixtures to direct-PRIMARY contract (task 5.1)
This commit is contained in:
parent
71ce41f486
commit
7f974e766b
11 changed files with 138 additions and 169 deletions
|
|
@ -2,9 +2,10 @@
|
|||
* test_ha_rdhup_integration.c — Task 6.4 integration test: RDHUP failover
|
||||
* end-to-end role transition.
|
||||
*
|
||||
* Tests verify the full RDHUP → CTRL_ELECTING → CTRL_PRIMARY_COMMITTING →
|
||||
* CTRL_PRIMARY state-machine chain using XCE_TESTING hook seams. No live
|
||||
* sockets or real cluster_t required.
|
||||
* Tests verify the full RDHUP → CTRL_ELECTING → CTRL_PRIMARY state-machine
|
||||
* chain (the election winner becomes primary directly — single leader role,
|
||||
* ha-single-leader-role) using XCE_TESTING hook seams. No live sockets or
|
||||
* real cluster_t required.
|
||||
*
|
||||
* Requirements: 6.3, 6.5, 9.2, 9.3 (Req numbers from tasks.md 5.2 / 6.4)
|
||||
*
|
||||
|
|
@ -68,7 +69,6 @@ static ha_config_t g_cfg = {
|
|||
.max_promotion_retries = 5,
|
||||
.election_jitter_max_ms = 0,
|
||||
.election_priority_step_ms = 500,
|
||||
.committing_timeout_ms = 10000,
|
||||
};
|
||||
|
||||
/* ── install_stubs / clear_stubs ─────────────────────────────────────────── */
|
||||
|
|
@ -155,13 +155,14 @@ static void make_cluster(cluster_t *c, myconf_t *myconf, const char *my_name)
|
|||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════════════════
|
||||
* Test 1: RDHUP → ELECTING → COMMITTING (no standbys present → via hook chain)
|
||||
* Test 1: RDHUP → ELECTING → PRIMARY (no standbys present → via hook chain)
|
||||
*
|
||||
* Req 6.3: RDHUP triggers CTRL_ELECTING + async election
|
||||
* Req 9.3: RDHUP election uses ha_start_election_async (not am_i_primary_quorum)
|
||||
* Req 9.2: phase2_done=1 suppresses cluster_init_phase2 on RDHUP re-election
|
||||
* Req 1.1: the election winner becomes CTRL_PRIMARY directly (single leader role)
|
||||
* ═════════════════════════════════════════════════════════════════════════ */
|
||||
static void test_rdhup_full_path_reaches_committing(void)
|
||||
static void test_rdhup_full_path_reaches_primary(void)
|
||||
{
|
||||
install_stubs();
|
||||
|
||||
|
|
@ -193,13 +194,14 @@ static void test_rdhup_full_path_reaches_committing(void)
|
|||
TEST_ASSERT_EQUAL_INT_MESSAGE(0, g_phase2_calls,
|
||||
"RDHUP re-election must not call cluster_init_phase2 when phase2_done=1 (Req 9.2)");
|
||||
|
||||
/* Role must be CTRL_PRIMARY_COMMITTING (quorum won → committing gate) */
|
||||
/* Role must be CTRL_PRIMARY directly — the election winner is the primary
|
||||
* (single leader role; no transitional sub-state, Req 1.1). */
|
||||
int role = (int)atomic_load_explicit(&c.ha.role, memory_order_acquire);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE((int)CTRL_PRIMARY_COMMITTING, role,
|
||||
"RDHUP full path must reach CTRL_PRIMARY_COMMITTING after winning election (Req 6.3)");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE((int)CTRL_PRIMARY, role,
|
||||
"RDHUP full path must reach CTRL_PRIMARY after winning election (Req 6.3, 1.1)");
|
||||
|
||||
ha_fini(&c.ha);
|
||||
printf("test_rdhup_full_path_reaches_committing: PASS (role=%d==CTRL_PRIMARY_COMMITTING)\n",
|
||||
printf("test_rdhup_full_path_reaches_primary: PASS (role=%d==CTRL_PRIMARY)\n",
|
||||
role);
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +213,7 @@ static void test_rdhup_full_path_reaches_committing(void)
|
|||
* ═════════════════════════════════════════════════════════════════════════ */
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════════════════
|
||||
* Test 3: RDHUP in single-node cluster → immediate PRIMARY (no COMMITTING)
|
||||
* Test 3: RDHUP in single-node cluster → immediate PRIMARY (single leader role)
|
||||
*
|
||||
* Req 9.1: single-node self-elects without network
|
||||
* n_peers=0 → quorum=1, threshold=0 → acks(0) >= 0 → promotes immediately
|
||||
|
|
@ -243,7 +245,7 @@ static void test_rdhup_single_node_reaches_primary(void)
|
|||
close(sv[1]);
|
||||
|
||||
/* n_peers=0 → ha_elect_evaluate_and_signal single-node shortcircuit lands
|
||||
* CTRL_PRIMARY directly (no transitional COMMITTING, no ack machinery —
|
||||
* CTRL_PRIMARY directly (no transitional leader sub-state, no ack machinery —
|
||||
* ha-single-leader-role). The old replication-ack fallback was excised
|
||||
* (function deleted task 4.1); the PRIMARY assertion stands on its own. */
|
||||
int role = (int)atomic_load_explicit(&c.ha.role, memory_order_acquire);
|
||||
|
|
@ -258,18 +260,18 @@ static void test_rdhup_single_node_reaches_primary(void)
|
|||
/* ═══════════════════════════════════════════════════════════════════════════
|
||||
* Test 4 (3-node RDHUP — ack-driven promotion) DELETED — ha-single-leader-role
|
||||
* task 4.1. Subject was the deleted ack-counting promotion machinery
|
||||
* (the replication-ack handler drives COMMITTING → PRIMARY on threshold acks);
|
||||
* the mechanism is gone, nothing left to verify. No shim (design §"Transitional-
|
||||
* State Deletions").
|
||||
* (the replication-ack handler promoted a transitional leader state to PRIMARY
|
||||
* on threshold acks); the mechanism is gone, nothing left to verify. No shim
|
||||
* (design §"Transitional-State Deletions").
|
||||
* ═════════════════════════════════════════════════════════════════════════ */
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════════════════
|
||||
* Test 5: config push and ctrlhello hooks fire during COMMITTING entry
|
||||
* Test 5: config push and ctrlhello hooks fire on promotion to primary
|
||||
*
|
||||
* Req 7.1: push_config_to_standbys called after winning election
|
||||
* Req 7.2: ha_send_ctrlhello_to_all_standbys called after winning election
|
||||
* ═════════════════════════════════════════════════════════════════════════ */
|
||||
static void test_rdhup_committing_fires_replication_hooks(void)
|
||||
static void test_rdhup_promotion_fires_replication_hooks(void)
|
||||
{
|
||||
install_stubs();
|
||||
|
||||
|
|
@ -293,13 +295,13 @@ static void test_rdhup_committing_fires_replication_hooks(void)
|
|||
close(sv[1]);
|
||||
|
||||
TEST_ASSERT_GREATER_THAN_INT_MESSAGE(0, g_push_config_calls,
|
||||
"push_config_to_standbys hook must fire when entering COMMITTING (Req 7.1)");
|
||||
"push_config_to_standbys hook must fire on promotion to primary (Req 7.1)");
|
||||
TEST_ASSERT_GREATER_THAN_INT_MESSAGE(0, g_ctrlhello_calls,
|
||||
"ha_send_ctrlhello hook must fire when entering COMMITTING (Req 7.2)");
|
||||
"ha_send_ctrlhello hook must fire on promotion to primary (Req 7.2)");
|
||||
|
||||
clear_stubs();
|
||||
ha_fini(&c.ha);
|
||||
printf("test_rdhup_committing_fires_replication_hooks: PASS "
|
||||
printf("test_rdhup_promotion_fires_replication_hooks: PASS "
|
||||
"(push=%d, ctrlhello=%d)\n",
|
||||
g_push_config_calls, g_ctrlhello_calls);
|
||||
}
|
||||
|
|
@ -348,8 +350,8 @@ static void test_rdhup_primary_dispatch_gate_opens(void)
|
|||
close(sv[1]);
|
||||
|
||||
/* ha-single-leader-role: ha_elect_evaluate_and_signal lands the winner in
|
||||
* CTRL_PRIMARY directly (no transitional COMMITTING, no ack machinery). The
|
||||
* old replication-ack drive-step was excised (function deleted task 4.1);
|
||||
* CTRL_PRIMARY directly (no transitional leader sub-state, no ack machinery).
|
||||
* The old replication-ack drive-step was excised (function deleted task 4.1);
|
||||
* the dispatch-gate assertion below is the subject of this case. */
|
||||
int role = (int)atomic_load_explicit(&c.ha.role, memory_order_acquire);
|
||||
TEST_ASSERT_EQUAL_INT((int)CTRL_PRIMARY, role);
|
||||
|
|
@ -375,12 +377,12 @@ static void test_rdhup_primary_dispatch_gate_opens(void)
|
|||
|
||||
void test_ha_rdhup_integration(void)
|
||||
{
|
||||
RUN_TEST(test_rdhup_full_path_reaches_committing);
|
||||
/* test_rdhup_committing_to_primary_on_ack deleted (ha-single-leader-role 4.1:
|
||||
RUN_TEST(test_rdhup_full_path_reaches_primary);
|
||||
/* ack-driven promotion test deleted (ha-single-leader-role 4.1:
|
||||
* ack-driven promotion machinery removed, no shim) */
|
||||
RUN_TEST(test_rdhup_single_node_reaches_primary);
|
||||
/* test_rdhup_3node_one_ack_promotes deleted (ha-single-leader-role 4.1:
|
||||
* ack-counting promotion machinery removed, no shim) */
|
||||
RUN_TEST(test_rdhup_committing_fires_replication_hooks);
|
||||
RUN_TEST(test_rdhup_promotion_fires_replication_hooks);
|
||||
RUN_TEST(test_rdhup_primary_dispatch_gate_opens);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue