From 6ad7136027c56c3a523278d90ade3da018e39273 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 18 Dec 2025 16:46:53 +0000 Subject: sync: turn off negentropy and fix some tests --- tests/sync/bootstrap.rs | 50 ++++++++++++++++++++++++++++++------------------- tests/sync/metrics.rs | 41 ++++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 25 deletions(-) (limited to 'tests/sync') diff --git a/tests/sync/bootstrap.rs b/tests/sync/bootstrap.rs index 174fe28..8f0c79b 100644 --- a/tests/sync/bootstrap.rs +++ b/tests/sync/bootstrap.rs @@ -33,26 +33,19 @@ async fn test_bootstrap_syncs_existing_layer2_events() { relay_a.domain() ); - // 2. Start syncing relay (relay_b) configured to sync from relay_a - let relay_b = TestRelay::start_with_sync(Some(relay_a.url().into())).await; - println!( - "relay_b started at {} (domain: {})", - relay_b.url(), - relay_b.domain() - ); + // 2. Pre-allocate port for relay_b so we can include it in the announcement + let relay_b_port = TestRelay::find_free_port(); + let relay_b_domain = format!("127.0.0.1:{}", relay_b_port); + println!("Pre-allocated relay_b domain: {}", relay_b_domain); // 3. Create test keys let keys = Keys::generate(); - // 4. Wait for relay_b's sync connection to establish - tokio::time::sleep(Duration::from_secs(1)).await; - - // 5. Create a repository announcement that lists BOTH relays - // This is required for sync - the event must reference both relays - // for the write policy to accept it on both sides + // 4. Create a repository announcement that lists BOTH relays + // This is required because relay_b's write policy checks that events reference its domain let announcement = create_repo_announcement( &keys, - &[&relay_a.domain(), &relay_b.domain()], + &[&relay_a.domain(), &relay_b_domain], "test-repo-bootstrap", ); let announcement_id = announcement.id; @@ -66,7 +59,8 @@ async fn test_bootstrap_syncs_existing_layer2_events() { println!(" Tag: {:?}", tag.as_slice()); } - // 6. Send announcement to relay_a + // 5. Send announcement to relay_a BEFORE relay_b starts + // This is key for testing bootstrap sync let client_a = TestClient::new(relay_a.url(), keys.clone()) .await .expect("Failed to connect to relay_a"); @@ -79,17 +73,35 @@ async fn test_bootstrap_syncs_existing_layer2_events() { client_a.disconnect().await; - // 7. Wait for sync to occur - tokio::time::sleep(Duration::from_secs(2)).await; + // 6. Wait briefly to ensure event is persisted on relay_a + tokio::time::sleep(Duration::from_millis(500)).await; - // 8. Verify announcement synced to relay_b + // 7. NOW start relay_b on the pre-allocated port, configured to sync from relay_a + // The announcement already exists on relay_a, so this tests bootstrap sync + let relay_b = TestRelay::start_on_port_with_options( + relay_b_port, + Some(relay_a.url().into()), + false, + ) + .await; + println!( + "relay_b started at {} (domain: {})", + relay_b.url(), + relay_b.domain() + ); + + // 8. Wait for bootstrap sync to complete + // Bootstrap sync should happen automatically on startup + tokio::time::sleep(Duration::from_secs(3)).await; + + // 9. Verify announcement synced to relay_b let filter = Filter::new() .kind(Kind::Custom(KIND_REPOSITORY_STATE)) .author(keys.public_key()); let synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await; - // 9. Cleanup + // 10. Cleanup relay_b.stop().await; relay_a.stop().await; diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index f1f19d0..e0e9d48 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs @@ -412,20 +412,30 @@ async fn test_connection_failure_increments_counter() { async fn test_live_sync_event_count() { let mut harness = MetricsTestHarness::with_sources(1).await; - // Start syncing BEFORE adding events - harness.start_syncing_relay(0).await; + // Pre-allocate syncing relay port to include in announcements + let sync_port = TestRelay::find_free_port(); + let sync_domain = format!("127.0.0.1:{}", sync_port); + + // Start syncing relay with pre-allocated port + harness.start_syncing_relay_on_port(0, sync_port).await; tokio::time::sleep(Duration::from_secs(2)).await; // Now add events - these should be "live" not "startup" + // Include BOTH domains so events are accepted by both relays let keys = Keys::generate(); let events: Vec<_> = (0..2) .map(|i| { - create_repo_announcement(&keys, &[&harness.source_domain(0)], &format!("live-{}", i)) + create_repo_announcement( + &keys, + &[&harness.source_domain(0), &sync_domain], + &format!("live-{}", i), + ) }) .collect(); harness.submit_events(0, &events).await.unwrap(); - tokio::time::sleep(Duration::from_secs(2)).await; + // Wait longer for live events to be processed and metrics updated + tokio::time::sleep(Duration::from_secs(4)).await; let metrics = harness.get_metrics().await.unwrap(); let live_count = metrics.events_total("live"); @@ -532,7 +542,25 @@ async fn test_multi_source_aggregate_counts() { // Note: Current impl only supports ONE sync source, so this tests // that with one source, tracked=1 and connected=1 let mut harness = MetricsTestHarness::with_sources(1).await; - harness.start_syncing_relay(0).await; + + // Pre-allocate syncing relay port and create an announcement that includes both domains + let sync_port = TestRelay::find_free_port(); + let sync_domain = format!("127.0.0.1:{}", sync_port); + + // Create announcement on source that references both relays + let keys = Keys::generate(); + let announcement = create_repo_announcement( + &keys, + &[&harness.source_domain(0), &sync_domain], + "test-repo", + ); + harness + .submit_events(0, &[announcement]) + .await + .unwrap(); + + // Now start syncing relay - it should sync the existing announcement + harness.start_syncing_relay_on_port(0, sync_port).await; tokio::time::sleep(Duration::from_secs(2)).await; let metrics = harness.get_metrics().await.unwrap(); @@ -553,7 +581,8 @@ async fn test_multi_source_aggregate_counts() { // Stop source, verify connected drops to 0 harness.stop_source(0).await; - tokio::time::sleep(Duration::from_secs(2)).await; + // Wait longer for disconnect to be detected and metrics updated + tokio::time::sleep(Duration::from_secs(4)).await; let metrics = harness.get_metrics().await.unwrap(); -- cgit v1.2.3