test(election-iomgr-refactor): add committing_timeout_fn watchdog unit tests — task 6.1

This commit is contained in:
Rongsong Shen 2026-05-30 13:19:31 +00:00
parent 27ea14cd9a
commit 0fdcd11e5f
2 changed files with 86 additions and 0 deletions

View file

@ -1638,6 +1638,29 @@ int election_timeout_fn_for_test(ha_state_t *ha, ha_elect_ctx_t *ctx,
pthread_mutex_unlock(&ctx->lock);
return 0;
}
/*
* committing_timeout_fn_for_test: test helper that exercises the committing
* timeout callback logic with an explicit cancelled_val. The cluster pointer
* may be NULL; the function checks the role on `ha` and calls
* ha_promote_to_primary(c) only when role == CTRL_PRIMARY_COMMITTING && c != NULL.
*
* Unlike the production callback, this shim does NOT free the ctx structure —
* it is stack/test-owned and must not be heap-freed by the shim.
*
* Returns 0 in all cases (mirrors the real callback).
*/
int committing_timeout_fn_for_test(ha_state_t *ha, cluster_t *c,
int cancelled_val)
{
if (cancelled_val)
return 0;
ctrl_role_t role = (ctrl_role_t)atomic_load_explicit(&ha->role,
memory_order_acquire);
if (role == CTRL_PRIMARY_COMMITTING && c != NULL)
ha_promote_to_primary(c);
return 0;
}
#endif /* XCE_TESTING */
/* ── Task 2.4: election_timeout_fn — delaymgr callback ─────────────────────