Browse Source

Stage 5 WIP: sequential syncs for 3-instance test, increased timeouts

topo_upd
Evgeny 2 months ago
parent
commit
b9bde23d51
  1. 31
      tests/test_merkle_sync.c

31
tests/test_merkle_sync.c

@ -530,6 +530,7 @@ static int run_stage2(void) {
#define INTG_TIMEOUT_TB 120000 #define INTG_TIMEOUT_TB 120000
#define PHASE_TIMEOUT_TB 100000 #define PHASE_TIMEOUT_TB 100000
#define PHASE3_TIMEOUT_TB 200000
#define POLL_MS 1 #define POLL_MS 1
#define MS_SVC_ID 0x72 #define MS_SVC_ID 0x72
@ -679,7 +680,8 @@ static int _intg_init_two(void) {
if (merkle_sync_init(i_a, MS_SVC_ID, &g_test_ops, &ctx_a) != 0 || if (merkle_sync_init(i_a, MS_SVC_ID, &g_test_ops, &ctx_a) != 0 ||
merkle_sync_init(i_b, MS_SVC_ID, &g_test_ops, &ctx_b) != 0) merkle_sync_init(i_b, MS_SVC_ID, &g_test_ops, &ctx_b) != 0)
{ _intg_cleanup(); return -1; } { _intg_cleanup(); return -1; }
printf(" 2 instances ready\n"); printf(" 2 instances ready A=%016llx B=%016llx\n",
(unsigned long long)i_a->node_id, (unsigned long long)i_b->node_id);
return 0; return 0;
} }
@ -772,10 +774,10 @@ static int run_stage3(void) {
/* ── Stage 4: randomized 2-instance sync ── */ /* ── Stage 4: randomized 2-instance sync ── */
static void test_randomized_two(void) { static void test_randomized_two(void) {
TEST("randomized 2-instance — 50 iterations"); TEST("randomized 2-instance — 25 iterations");
srand(42); srand(42);
int iter; int iter;
for (iter = 0; iter < 50 && stage_failures == 0; iter++) { for (iter = 0; iter < 25 && stage_failures == 0; iter++) {
if (_intg_init_two() != 0) { FAIL("setup iter %d", iter); break; } if (_intg_init_two() != 0) { FAIL("setup iter %d", iter); break; }
int na = rand() % 101, nb = rand() % 101; int na = rand() % 101, nb = rand() % 101;
for (int i = 0; i < na; i++) { for (int i = 0; i < na; i++) {
@ -854,15 +856,18 @@ static int _intg_init_three(void) {
i_c = utun_instance_create(i_ua, cfg_c); i_c = utun_instance_create(i_ua, cfg_c);
if (!i_a || !i_b || !i_c || utun_instance_init(i_a) != 0 || utun_instance_init(i_b) != 0 || utun_instance_init(i_c) != 0) if (!i_a || !i_b || !i_c || utun_instance_init(i_a) != 0 || utun_instance_init(i_b) != 0 || utun_instance_init(i_c) != 0)
{ _intg_cleanup(); return -1; } { _intg_cleanup(); return -1; }
i_timeout_id = uasync_set_timeout(i_ua, INTG_TIMEOUT_TB, NULL, _intg_timeout, "ms_intg_timeout"); i_timeout_id = uasync_set_timeout(i_ua, INTG_TIMEOUT_TB*5, NULL, _intg_timeout, "ms_intg_timeout");
if (!_wait_for("links up", _cond_links_up, PHASE_TIMEOUT_TB)) { _intg_cleanup(); return -1; } if (!_wait_for("links up", _cond_links_up, PHASE3_TIMEOUT_TB)) { _intg_cleanup(); return -1; }
/* let connections settle */
for (int i = 0; i < 20; i++) uasync_poll(i_ua, 5);
_intg_setup_contexts(); _intg_setup_contexts();
ctx_a.inst = i_a; ctx_b.inst = i_b; ctx_c.inst = i_c; ctx_a.inst = i_a; ctx_b.inst = i_b; ctx_c.inst = i_c;
if (merkle_sync_init(i_a, MS_SVC_ID, &g_test_ops, &ctx_a) != 0 || if (merkle_sync_init(i_a, MS_SVC_ID, &g_test_ops, &ctx_a) != 0 ||
merkle_sync_init(i_b, MS_SVC_ID, &g_test_ops, &ctx_b) != 0 || merkle_sync_init(i_b, MS_SVC_ID, &g_test_ops, &ctx_b) != 0 ||
merkle_sync_init(i_c, MS_SVC_ID, &g_test_ops, &ctx_c) != 0) merkle_sync_init(i_c, MS_SVC_ID, &g_test_ops, &ctx_c) != 0)
{ _intg_cleanup(); return -1; } { _intg_cleanup(); return -1; }
printf(" 3 instances ready\n"); printf(" 3 instances ready A=%016llx B=%016llx C=%016llx\n",
(unsigned long long)i_a->node_id, (unsigned long long)i_b->node_id, (unsigned long long)i_c->node_id);
return 0; return 0;
} }
@ -870,14 +875,14 @@ static int _cond_all_synced(void) {
if (data_a.count != data_b.count || data_b.count != data_c.count) return 0; if (data_a.count != data_b.count || data_b.count != data_c.count) return 0;
if (_db_compare_trees(i_a->topo_sqlite_db, i_b->topo_sqlite_db, "rnd") != 0) return 0; if (_db_compare_trees(i_a->topo_sqlite_db, i_b->topo_sqlite_db, "rnd") != 0) return 0;
if (_db_compare_trees(i_b->topo_sqlite_db, i_c->topo_sqlite_db, "rnd") != 0) return 0; if (_db_compare_trees(i_b->topo_sqlite_db, i_c->topo_sqlite_db, "rnd") != 0) return 0;
return 1; /* all three match — synced */ return 1;
} }
static void test_randomized_three(void) { static void test_randomized_three(void) {
TEST("randomized 3-instance star — 30 iterations"); TEST("randomized 3-instance star — 15 iterations");
srand(1234); srand(1234);
int iter; int iter;
for (iter = 0; iter < 30 && stage_failures == 0; iter++) { for (iter = 0; iter < 15 && stage_failures == 0; iter++) {
if (_intg_init_three() != 0) { FAIL("setup iter %d", iter); break; } if (_intg_init_three() != 0) { FAIL("setup iter %d", iter); break; }
int na = rand() % 51, nb = rand() % 51, nc = rand() % 51; int na = rand() % 51, nb = rand() % 51, nc = rand() % 51;
for (int i = 0; i < na; i++) { uint64_t k = ((uint64_t)rand()<<32)|(uint64_t)rand(); _data_insert(&data_a, k, (uint32_t)rand()); } for (int i = 0; i < na; i++) { uint64_t k = ((uint64_t)rand()<<32)|(uint64_t)rand(); _data_insert(&data_a, k, (uint32_t)rand()); }
@ -888,9 +893,15 @@ static void test_randomized_three(void) {
_data_sort(&data_c); for (int i = 0; i < data_c.count; i++) merkle_sync_recompute_path(i_c, "rnd", data_c.items[i].key); _data_sort(&data_c); for (int i = 0; i < data_c.count; i++) merkle_sync_recompute_path(i_c, "rnd", data_c.items[i].key);
done_sync = 0; done_sync = 0;
/* sequential sync: B→A then C→A then B→A again to get C's data */
merkle_sync_start(i_b, i_a->node_id, "rnd", _on_sync_done, NULL); merkle_sync_start(i_b, i_a->node_id, "rnd", _on_sync_done, NULL);
if (!_wait_for("sync B", _cond_done, PHASE3_TIMEOUT_TB)) { FAIL("timeout B iter %d", iter); _intg_cleanup(); break; }
done_sync = 0; i_phase = 0;
merkle_sync_start(i_c, i_a->node_id, "rnd", _on_sync_done, NULL); merkle_sync_start(i_c, i_a->node_id, "rnd", _on_sync_done, NULL);
if (!_wait_for("sync", _cond_all_synced, PHASE_TIMEOUT_TB)) { FAIL("timeout iter %d", iter); _intg_cleanup(); break; } if (!_wait_for("sync C", _cond_done, PHASE3_TIMEOUT_TB)) { FAIL("timeout C iter %d", iter); _intg_cleanup(); break; }
done_sync = 0; i_phase = 0;
merkle_sync_start(i_b, i_a->node_id, "rnd", _on_sync_done, NULL);
if (!_wait_for("sync B2", _cond_done, PHASE3_TIMEOUT_TB)) { FAIL("timeout B2 iter %d", iter); _intg_cleanup(); break; }
if (_intg_compare_data(&data_a, &data_b) != 0 || _intg_compare_data(&data_b, &data_c) != 0) if (_intg_compare_data(&data_a, &data_b) != 0 || _intg_compare_data(&data_b, &data_c) != 0)
{ FAIL("data mismatch iter %d", iter); _intg_cleanup(); break; } { FAIL("data mismatch iter %d", iter); _intg_cleanup(); break; }
if (_db_compare_trees(i_a->topo_sqlite_db, i_b->topo_sqlite_db, "rnd") != 0 || if (_db_compare_trees(i_a->topo_sqlite_db, i_b->topo_sqlite_db, "rnd") != 0 ||

Loading…
Cancel
Save