/* * test_netio_reconnect_gen.c — TDD tests for endpoint_t.reconnect_gen. * * component-failover-adoption Phase 6 (bug-1548): a monotonic counter bumped * by xce_ctx_reconnect() (xcectx.c) on every successful transport reconnect, * so a consumer (apiserver's heartbeat prober) can detect a reconnect even * when it completed silently inside a single XCECLI_FF_CALL and the call's * own return code never surfaced a failure. * * Mirrors test_netio_on_fini.c's structure for the same class of field * (a passive observation point added to endpoint_t). These tests exercise * only the field's lifecycle guarantees at the netio.c level — they do NOT * exercise xce_ctx_reconnect() itself (that requires a live socket/SSL * handshake) and are not a substitute for the required live E2E re-run of * task 5.2's scenario. Tests verify: * 1. A freshly heap-allocated endpoint_t starts with reconnect_gen == 0 * 2. endpoint_init() does not reset a previously-bumped value * 3. endpoint_fini() does not reset a previously-bumped value */ #define _GNU_SOURCE #include #include #include #include #include "netio.h" /* ── Test 1: fresh endpoint_t starts at zero ─────────────────────── */ static void test_reconnect_gen_starts_at_zero(void) { endpoint_t *ep = endpoint_get(); TEST_ASSERT_NOT_NULL(ep); TEST_ASSERT_EQUAL_UINT64(0, ep->reconnect_gen); free(ep); printf("test_reconnect_gen_starts_at_zero: PASS\n"); } /* ── Test 2: endpoint_init() does not reset a bumped value ───────── */ static void test_reconnect_gen_survives_endpoint_init(void) { endpoint_t *ep = endpoint_get(); TEST_ASSERT_NOT_NULL(ep); ep->reconnect_gen = 7; int fd = endpoint_init(ep, AF_INET, SOCK_STREAM, 0, 0); TEST_ASSERT_TRUE(fd >= 0); TEST_ASSERT_EQUAL_UINT64(7, ep->reconnect_gen); endpoint_fini(ep); free(ep); printf("test_reconnect_gen_survives_endpoint_init: PASS\n"); } /* ── Test 3: endpoint_fini() does not reset a bumped value ───────── */ static void test_reconnect_gen_survives_endpoint_fini(void) { endpoint_t *ep = endpoint_get(); TEST_ASSERT_NOT_NULL(ep); int fd = endpoint_init(ep, AF_INET, SOCK_STREAM, 0, 0); TEST_ASSERT_TRUE(fd >= 0); ep->reconnect_gen = 3; endpoint_fini(ep); TEST_ASSERT_EQUAL_UINT64(3, ep->reconnect_gen); free(ep); printf("test_reconnect_gen_survives_endpoint_fini: PASS\n"); } /* ── Test suite entry point ───────────────────────────────────────── */ void test_netio_reconnect_gen(void) { printf("\n>> netio reconnect_gen field lifecycle tests\n\n"); RUN_TEST(test_reconnect_gen_starts_at_zero); RUN_TEST(test_reconnect_gen_survives_endpoint_init); RUN_TEST(test_reconnect_gen_survives_endpoint_fini); }