feat(controller-status): render responderTime in cmd_ctrlstatus, log-comparable format (task 6.3)
Add ctrlstatus_fmt.h (ctrlstatus_format_time_ms): renders responder_time_ms as local YYYY-MM-DD HH:MM:SS,mmm, byte-equivalent to the controller log prefix (tlog/my_tlog_format) so a captured ctrlstatus lines up against ctrl-N.log. cmd_ctrlstatus prints a responderTime line; TZ-pinned exact-string unit test. Req 11.2, 11.3. ctrlstatus group passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3799bd6af4
commit
ee30765d31
4 changed files with 115 additions and 1 deletions
|
|
@ -8,7 +8,9 @@
|
|||
* 5.1, 5.2, 5.3, 6.1, 6.2, 6.3, 6.4.
|
||||
*/
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* setenv */
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
|
|
@ -20,6 +22,8 @@
|
|||
#include "persist.h"
|
||||
#include "xce/cluster_def.h"
|
||||
|
||||
#include "ctrlstatus_fmt.h" /* ctrlstatus_format_time_ms (task 6.3) */
|
||||
|
||||
/* ── helpers ────────────────────────────────────────────────── */
|
||||
|
||||
static ha_config_t cs_valid_cfg(void)
|
||||
|
|
@ -474,10 +478,41 @@ static void test_ctrlstatus_responder_time_ms(void)
|
|||
printf("test_ctrlstatus_responder_time_ms: PASS\n");
|
||||
}
|
||||
|
||||
/* (j) Responder snapshot timestamp rendering (Req 11.2, 11.3): the test client
|
||||
* renders responder_time_ms (epoch-millis) into the SAME wall-clock string the
|
||||
* controller logger (tlog) emits — local-time "YYYY-MM-DD HH:MM:SS,mmm" — so it
|
||||
* is byte-comparable against ctrl-N.log. Pin TZ=UTC for determinism, then assert
|
||||
* the exact rendered string for a known epoch-millis. */
|
||||
static void test_ctrlstatus_format_time_ms(void)
|
||||
{
|
||||
setenv("TZ", "UTC", 1);
|
||||
tzset();
|
||||
|
||||
/* 1781939830000 ms == 2026-06-20 07:17:10 UTC; +911 ms of fractional part.
|
||||
* Renders local time (TZ=UTC) in the tlog prefix shape "%.4d-%.2d-%.2d
|
||||
* %.2d:%.2d:%.2d,%.3d". */
|
||||
char buf[64];
|
||||
uint64_t ms = UINT64_C(1781939830000) + 911u;
|
||||
|
||||
char* ret = ctrlstatus_format_time_ms(ms, buf, sizeof(buf));
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(buf, ret);
|
||||
TEST_ASSERT_EQUAL_STRING("2026-06-20 07:17:10,911", buf);
|
||||
|
||||
/* zero-millis fractional part must still be zero-padded to 3 digits */
|
||||
char* ret2 = ctrlstatus_format_time_ms(UINT64_C(1781939830000), buf,
|
||||
sizeof(buf));
|
||||
TEST_ASSERT_EQUAL_PTR(buf, ret2);
|
||||
TEST_ASSERT_EQUAL_STRING("2026-06-20 07:17:10,000", buf);
|
||||
|
||||
printf("test_ctrlstatus_format_time_ms: PASS\n");
|
||||
}
|
||||
|
||||
/* ── suite entry point ─────────────────────────────────────── */
|
||||
|
||||
void test_ctrlstatus(void)
|
||||
{
|
||||
RUN_TEST(test_ctrlstatus_format_time_ms);
|
||||
RUN_TEST(test_ctrlstatus_primary);
|
||||
RUN_TEST(test_ctrlstatus_standby_known_primary);
|
||||
RUN_TEST(test_ctrlstatus_unknown_primary);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue