From 274f4f2d63e8773298b91b4066e7c6b86c51721b Mon Sep 17 00:00:00 2001 From: evgeny Date: Sun, 4 Oct 2026 16:47:01 +0200 Subject: [PATCH] Prepare explicit group sessions in history protocol fixtures --- tests/test_chat_sync_stress.c | 7 ++++-- tests/test_db_sync.c | 39 ++++++++++++++++++++------------ tests/test_media_delivery_chat.c | 3 ++- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/tests/test_chat_sync_stress.c b/tests/test_chat_sync_stress.c index 938ded92..971348c2 100644 --- a/tests/test_chat_sync_stress.c +++ b/tests/test_chat_sync_stress.c @@ -128,6 +128,8 @@ static void seed_members(struct UTUN_INSTANCE* self, struct UTUN_INSTANCE* peer) uint8_t z32[32] = {0}, z64[64] = {0}; topo_node_sqlite_channel_put(db, ch_id, INSTANCE_NAME, 0, z32, NULL, z32, NULL, z64); topo_node_sqlite_member_placeholder_put(db, ch_id, peer->node_id, z32, z32); + if (!topo_groups_find(self->topo_groups, INSTANCE_ID)) + topo_groups_create_group(self->topo_groups, INSTANCE_ID, TOPO_GROUP_TYPE_CHAT, ch_id); } static int insert_record(struct DB_SYNC_INSTANCE* si, struct UTUN_INSTANCE* inst, const char* data, size_t len) { @@ -164,9 +166,10 @@ int main(void) { } seed_members(inst_a, inst_b); seed_members(inst_b, inst_a); - si_a = db_sync_instance_add(inst_a, INSTANCE_NAME, INSTANCE_ID, 1); - si_b = db_sync_instance_add(inst_b, INSTANCE_NAME, INSTANCE_ID, 1); + si_a = db_sync_instance_add(inst_a, INSTANCE_NAME, INSTANCE_ID); + si_b = db_sync_instance_add(inst_b, INSTANCE_NAME, INSTANCE_ID); if (!si_a || !si_b) { DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "db_sync_instance_add"); return 1; } + db_sync_instance_set_gated(si_a, 0); db_sync_instance_set_gated(si_b, 0); timeout_id = uasync_set_timeout(ua, TOTAL_TIMEOUT_TB, NULL, test_timeout, "total_timeout"); uint64_t t0 = get_time_tb(); diff --git a/tests/test_db_sync.c b/tests/test_db_sync.c index caf14a39..2f84cd33 100644 --- a/tests/test_db_sync.c +++ b/tests/test_db_sync.c @@ -22,6 +22,7 @@ #include "routing.h" #include "topo_node.h" #include "topo_node_sqlite.h" +#include "../src/routing_layer/topo_group.h" #include "../src/tun_if.h" #include "secure_channel.h" #include "secure_channel.h" @@ -206,9 +207,19 @@ static void seed_members(struct UTUN_INSTANCE* self, struct UTUN_INSTANCE** peer for (int i = 0; i < peer_count; i++) if (peers[i] && peers[i]->node_id) topo_node_sqlite_member_placeholder_put(db, groups[gi], peers[i]->node_id, z32, z32); + uint64_t gid = strtoull(groups[gi], NULL, 10); + if (!topo_groups_find(self->topo_groups, gid)) + topo_groups_create_group(self->topo_groups, gid, TOPO_GROUP_TYPE_CHAT, groups[gi]); } } +/* Протокольные тесты сами подготовили участников; включение обмена явно отделено от регистрации. */ +static struct DB_SYNC_INSTANCE* add_table(struct UTUN_INSTANCE* inst, const char* table, uint64_t gid) { + struct DB_SYNC_INSTANCE* si = db_sync_instance_add(inst, table, gid); + if (si) db_sync_instance_set_gated(si, 0); + return si; +} + int main(void) { printf("=== test_db_sync ===\n"); debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); @@ -235,8 +246,8 @@ int main(void) { // =================================================================== printf("Phase 1: peer_empty\n"); reset_done_flags(); - si_a = db_sync_instance_add(inst_a, "test", 1, 0); - si_b = db_sync_instance_add(inst_b, "test", 1, 0); + si_a = add_table(inst_a, "test", 1); + si_b = add_table(inst_b, "test", 1); if (!si_a || !si_b) { test_phase = 2; goto done; } if (insert_many(si_a, inst_a, 0, 5) != 0) { test_phase = 2; goto done; } db_sync_reinitiate(si_b, inst_a->node_id); @@ -269,8 +280,8 @@ int main(void) { printf("Phase 3: divergence merge\n"); reset_done_flags(); remove_si(&si_a); remove_si(&si_b); - si_a = db_sync_instance_add(inst_a, "test2", 2, 0); - si_b = db_sync_instance_add(inst_b, "test2", 2, 0); + si_a = add_table(inst_a, "test2", 2); + si_b = add_table(inst_b, "test2", 2); if (!si_a || !si_b) { test_phase = 2; goto done; } if (insert_many(si_a, inst_a, 0, 3) != 0 || insert_many(si_b, inst_b, 10, 2) != 0) { test_phase = 2; goto done; } @@ -287,8 +298,8 @@ int main(void) { printf("Phase 4: divergence merge 2\n"); reset_done_flags(); remove_si(&si_a); remove_si(&si_b); - si_a = db_sync_instance_add(inst_a, "test_div", 30, 0); - si_b = db_sync_instance_add(inst_b, "test_div", 30, 0); + si_a = add_table(inst_a, "test_div", 30); + si_b = add_table(inst_b, "test_div", 30); if (!si_a || !si_b) { test_phase = 2; goto done; } if (insert_many(si_a, inst_a, 0, 2) != 0 || insert_many(si_b, inst_b, 10, 2) != 0) { test_phase = 2; goto done; } @@ -305,8 +316,8 @@ int main(void) { printf("Phase 5: PUSH not-at-tail\n"); reset_done_flags(); remove_si(&si_a); remove_si(&si_b); - si_a = db_sync_instance_add(inst_a, "push_t", 40, 1); - si_b = db_sync_instance_add(inst_b, "push_t", 40, 1); + si_a = add_table(inst_a, "push_t", 40); + si_b = add_table(inst_b, "push_t", 40); if (!si_a || !si_b) { test_phase = 2; goto done; } if (insert_many(si_a, inst_a, 0, 2) != 0) { test_phase = 2; goto done; } cb_target = 2; @@ -343,9 +354,9 @@ int main(void) { if (!wait_for("C links up", cond_links_init, PHASE_TIMEOUT_TB)) { test_phase = 2; goto done; } if (!wait_for("pubkeys", cond_pubkeys_ready, PHASE_TIMEOUT_TB)) { test_phase = 2; goto done; } - si_a = db_sync_instance_add(inst_a, "triple", 70, 0); - si_b = db_sync_instance_add(inst_b, "triple", 70, 0); - si_c = db_sync_instance_add(inst_c, "triple", 70, 0); + si_a = add_table(inst_a, "triple", 70); + si_b = add_table(inst_b, "triple", 70); + si_c = add_table(inst_c, "triple", 70); if (!si_a || !si_b || !si_c) { test_phase = 2; goto done; } if (insert_many(si_a, inst_a, 0, 2) != 0 || insert_many(si_b, inst_b, 10, 1) != 0 || insert_many(si_c, inst_c, 20, 1) != 0) { test_phase = 2; goto done; } @@ -394,9 +405,9 @@ int main(void) { srand((unsigned)time(NULL)); printf("seed=%u\n", (unsigned)time(NULL)); - si_a = db_sync_instance_add(inst_a, "rnd_triple", 80, 0); - si_b = db_sync_instance_add(inst_b, "rnd_triple", 80, 0); - si_c = db_sync_instance_add(inst_c, "rnd_triple", 80, 0); + si_a = add_table(inst_a, "rnd_triple", 80); + si_b = add_table(inst_b, "rnd_triple", 80); + si_c = add_table(inst_c, "rnd_triple", 80); if (!si_a || !si_b || !si_c) { test_phase = 2; goto done; } // -- Round 1: cold start divergence merge with 0..20 random records per peer -- diff --git a/tests/test_media_delivery_chat.c b/tests/test_media_delivery_chat.c index a55f179a..232ee2e7 100644 --- a/tests/test_media_delivery_chat.c +++ b/tests/test_media_delivery_chat.c @@ -506,8 +506,9 @@ static void setup_db_sync(void) { TEST("db_sync instances on all nodes"); { int ok = 1; for (int i = 0; i < N_NODES; i++) { - g_si[i] = db_sync_instance_add(g_inst[i], "msg_" CH_ID, g_group_id, 1); + g_si[i] = db_sync_instance_add(g_inst[i], "msg_" CH_ID, g_group_id); if (!g_si[i]) { ok = 0; DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "[mdc] db_sync_instance_add failed node=%d", i); } + else db_sync_instance_set_gated(g_si[i], 0); } if (ok) OK(); else FAIL(); }