- Add `persist_t persist` field to cluster_t (cluster_def.h includes persist.h) - Add `workdir` and `name` fields to myconf_t; main.c passes them through - cluster_init: call persist_set_workdir, persist_init, persist_recover after apiserver_init - cluster_start: call persist_start (launches fsync thread + registers WAL hooks) - cluster_fini: call persist_stop + persist_fini before delaymgr/vtaskmgr teardown - persist_init: store cluster back-pointer (replaces (void)c stub) - persist_start: register persist_job/queue/worker_hook_fun via xce_add_hook when cluster != NULL - Add test_cluster_persist.c: compile-time struct check + config defaults + workdir path derivation - Register test in controller_test.c and meson.build All controller tests pass (1/1 OK, 50s).
103 lines
3.6 KiB
C
103 lines
3.6 KiB
C
#define _GNU_SOURCE
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <unity/unity.h>
|
|
|
|
#include "config.h"
|
|
#include "persist.h"
|
|
#include "xce/cluster_def.h"
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Compile-time structural checks */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
static void test_cluster_t_has_persist_field(void)
|
|
{
|
|
/* Verify cluster_t has a persist field — compile-time structural check.
|
|
* If persist_t persist is not in cluster_t, this will fail to compile. */
|
|
cluster_t c;
|
|
memset(&c, 0, sizeof(c));
|
|
/* Access the persist field to confirm it exists at compile time */
|
|
(void)c.persist.current_lsn;
|
|
TEST_PASS_MESSAGE("cluster_t has persist field");
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* persist_config_defaults() correctness */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
static void test_persist_config_defaults_wal_sync_ms(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_WAL_SYNC_MS, cfg.wal_sync_ms);
|
|
}
|
|
|
|
static void test_persist_config_defaults_snap_interval_s(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SNAP_INTERVAL_S, cfg.snap_interval_s);
|
|
}
|
|
|
|
static void test_persist_config_defaults_snap_wal_size_mb(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SNAP_WAL_SIZE_MB, cfg.snap_wal_size_mb);
|
|
}
|
|
|
|
static void test_persist_config_defaults_snap_keep_n(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SNAP_KEEP_N, cfg.snap_keep_n);
|
|
}
|
|
|
|
static void test_persist_config_defaults_finished_retain_s(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_FINISHED_RETAIN_S, cfg.finished_retain_s);
|
|
}
|
|
|
|
static void test_persist_config_defaults_sync_timeout_ms(void)
|
|
{
|
|
persist_config_t cfg = persist_config_defaults();
|
|
TEST_ASSERT_EQUAL_UINT32(DEFAULT_SYNC_TIMEOUT_MS, cfg.sync_timeout_ms);
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* persist_set_workdir derives correct paths */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
static void test_persist_set_workdir_derives_wal_path(void)
|
|
{
|
|
persist_t p;
|
|
memset(&p, 0, sizeof(p));
|
|
persist_set_workdir(&p, "/tmp/xce", "ctrl1");
|
|
TEST_ASSERT_EQUAL_STRING("/tmp/xce/ctrl1/data/wal", p.wal_path);
|
|
}
|
|
|
|
static void test_persist_set_workdir_derives_snap_path(void)
|
|
{
|
|
persist_t p;
|
|
memset(&p, 0, sizeof(p));
|
|
persist_set_workdir(&p, "/tmp/xce", "ctrl1");
|
|
TEST_ASSERT_EQUAL_STRING("/tmp/xce/ctrl1/data/snap", p.snap_path);
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Suite entry point */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
void test_cluster_persist(void)
|
|
{
|
|
printf("\n>> cluster persist wiring tests (P0-F)\n\n");
|
|
|
|
RUN_TEST(test_cluster_t_has_persist_field);
|
|
RUN_TEST(test_persist_config_defaults_wal_sync_ms);
|
|
RUN_TEST(test_persist_config_defaults_snap_interval_s);
|
|
RUN_TEST(test_persist_config_defaults_snap_wal_size_mb);
|
|
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_persist_set_workdir_derives_wal_path);
|
|
RUN_TEST(test_persist_set_workdir_derives_snap_path);
|
|
}
|