From a6973f99979aa95e6eddb65259785d64ec18e709 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 29 Oct 2026 21:34:02 +0100 Subject: [PATCH] Model accepted sends in the ETCP lifecycle fixture --- tests/test_etcp_server_lifecycle.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_etcp_server_lifecycle.c b/tests/test_etcp_server_lifecycle.c index 8d66bab5d..6ea8e7355 100644 --- a/tests/test_etcp_server_lifecycle.c +++ b/tests/test_etcp_server_lifecycle.c @@ -4,6 +4,7 @@ #include "etcp.h" #include "etcp_api.h" #include "etcp_keepalive.h" +#include "etcp_link_io.h" #include "node_conn_direct.h" #include "utun_instance.h" #include "config_parser.h" @@ -18,6 +19,16 @@ static struct utun_config cfg; static struct ETCP_SOCKET sock; static unsigned deleted, closed, down; static int release_on_down; +static int send_result; + +/* Тестируем жизненный цикл без сетевого I/O; результат принятия пакета задаёт фикстура. */ +static int fixture_send(struct ETCP_DGRAM* packet) { + CHECK(packet && packet->data_len); + DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "Lifecycle send: link=%u bytes=%u result=%d", + packet->link->local_link_id, packet->data_len, send_result); + return send_result < 0 ? send_result : (int)packet->data_len; +} +static const struct etcp_link_codec fixture_codec = {.send = fixture_send}; static void deleted_cb(struct ETCP_CONN* conn, int event, void* arg) { (void)conn; (void)event; (void)arg; deleted++; @@ -36,7 +47,7 @@ static void owner_cb(struct NODE_CONN_DIRECT* handle, enum ncd_event event, void static void setup(void) { memset(&inst, 0, sizeof(inst)); memset(&cfg, 0, sizeof(cfg)); memset(&sock, 0, sizeof(sock)); - deleted = closed = down = 0; release_on_down = 0; + deleted = closed = down = 0; release_on_down = send_result = 0; inst.node_id = UINT64_C(0x0123456789abcdef); inst.ua = uasync_create(); CHECK(inst.ua); inst.config = &cfg; cfg.global.bbr_max_cwnd = 100000; cfg.global.keepalive_interval = 200; cfg.global.keepalive_timeout = 2000; @@ -70,6 +81,7 @@ static struct ETCP_CONN* new_conn(void) { static struct ETCP_LINK* add_link(struct ETCP_CONN* conn, int tcp) { struct ETCP_LINK* link = u_calloc(1, sizeof(*link)); CHECK(link); link->etcp = conn; link->conn = &sock; link->is_server = 1; link->is_tcp = tcp; + link->codec = &fixture_codec; link->initialized = link->link_status = link->recv_keepalive = link->remote_keepalive = 1; link->link_state = LINK_STATE_CONNECTED; link->keepalive_interval = link->ka_period_ms = 200; link->keepalive_timeout = 2000; link->last_recv_local_time = get_time_tb(); @@ -302,6 +314,17 @@ static void check_peer_wake_reordered(void) { teardown(); DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "PASS normal keepalive restores awake state after loss and reordered sleep"); } +/* Счётчик keepalive отражает только принятые транспортом пакеты, включая busy и ошибку. */ +static void check_keepalive_send_result(void) { + setup(); struct ETCP_CONN* conn = ready_conn(0); struct ETCP_LINK* link = conn->links; + unsigned sent = link->keepalive_sent_count; + for (send_result = -2; send_result <= 0; send_result++) { + etcp_link_send_keepalive(link); + CHECK(link->keepalive_sent_count == sent + (send_result == 0)); + } + teardown(); DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "PASS keepalive counts accepted send only; busy/error preserve counter"); +} + /* Мягкое закрытие работает без NCD entry; KEEP_ALIVE сохраняет транспорт дольше прежних 5 секунд. */ static void check_graceful(void) { setup(); struct ETCP_CONN* conn = ready_conn(0); @@ -341,6 +364,7 @@ int main(void) { check_peer_wake_new_link(tcp, active); CHECK(u_get_allocated_count() == baseline); } check_peer_wake_reordered(); CHECK(u_get_allocated_count() == baseline); + check_keepalive_send_result(); CHECK(u_get_allocated_count() == baseline); check_remote_down(); CHECK(u_get_allocated_count() == baseline); check_graceful(); CHECK(u_get_allocated_count() == baseline); test_clock_finish(); return 0;