feat(ha-commit-durability): add --wal-sync-ms flush-cadence override (task 1.1)

This commit is contained in:
Rongsong Shen 2026-06-18 04:46:01 +00:00
parent 80bb1d766e
commit 1ca2d640cb
7 changed files with 206 additions and 0 deletions

View file

@ -68,6 +68,44 @@ static void test_persist_config_defaults_sync_timeout_ms(void)
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SYNC_TIMEOUT_MS, cfg.sync_timeout_ms);
}
/* ------------------------------------------------------------------ */
/* --wal-sync-ms flush-cadence override (ha-commit-durability task 1.1) */
/* */
/* persist_config_set_wal_sync_ms() is the single override point shared */
/* by both persist_config_defaults() callers (cluster.c phase2 and */
/* myapp.c step 6). It mirrors the --sync-timeout-ms convention: a */
/* value of 0 means "flag not passed" and preserves the default; a */
/* positive value sets the flush cadence to exactly that. */
/* ------------------------------------------------------------------ */
static void test_wal_sync_ms_override_applies_positive_value(void)
{
persist_config_t cfg = persist_config_defaults();
persist_config_set_wal_sync_ms(&cfg, 250);
TEST_ASSERT_EQUAL_UINT32(250, cfg.wal_sync_ms);
}
static void test_wal_sync_ms_override_zero_preserves_default(void)
{
persist_config_t cfg = persist_config_defaults();
/* 0 = flag omitted: cadence must stay byte-for-byte the default
* (Req 3.3 — the seam changes timing controllability only). */
persist_config_set_wal_sync_ms(&cfg, 0);
TEST_ASSERT_EQUAL_UINT32(DEFAULT_WAL_SYNC_MS, cfg.wal_sync_ms);
}
static void test_wal_sync_ms_override_leaves_other_fields_intact(void)
{
persist_config_t cfg = persist_config_defaults();
persist_config_set_wal_sync_ms(&cfg, 7);
/* Only the cadence changes; every other persistence default is
* preserved (Req 3.3 — no behavioral change beyond timing). */
TEST_ASSERT_EQUAL_UINT32(7, cfg.wal_sync_ms);
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SNAP_INTERVAL_S, cfg.snap_interval_s);
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SYNC_TIMEOUT_MS, cfg.sync_timeout_ms);
TEST_ASSERT_EQUAL_UINT32(DEFAULT_MAX_WAL_RECORDS, cfg.max_wal_records);
}
/* ------------------------------------------------------------------ */
/* persist_set_workdir derives correct paths */
/* ------------------------------------------------------------------ */
@ -103,6 +141,9 @@ void test_cluster_persist(void)
RUN_TEST(test_persist_config_defaults_snap_keep_n);
RUN_TEST(test_persist_config_defaults_finished_retain_s);
RUN_TEST(test_persist_config_defaults_sync_timeout_ms);
RUN_TEST(test_wal_sync_ms_override_applies_positive_value);
RUN_TEST(test_wal_sync_ms_override_zero_preserves_default);
RUN_TEST(test_wal_sync_ms_override_leaves_other_fields_intact);
RUN_TEST(test_persist_set_workdir_derives_wal_path);
RUN_TEST(test_persist_set_workdir_derives_snap_path);
}