upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/sync
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 16:46:53 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 16:46:53 +0000
commit6ad7136027c56c3a523278d90ade3da018e39273 (patch)
treedad50501b2085c320a9316e17928b584cc8ec80b /tests/sync
parent11a656fa96d6f60e2d8e8fd31657e24d6cc7cf21 (diff)
sync: turn off negentropy and fix some tests
Diffstat (limited to 'tests/sync')
-rw-r--r--tests/sync/bootstrap.rs50
-rw-r--r--tests/sync/metrics.rs41
2 files changed, 66 insertions, 25 deletions
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() {
33 relay_a.domain() 33 relay_a.domain()
34 ); 34 );
35 35
36 // 2. Start syncing relay (relay_b) configured to sync from relay_a 36 // 2. Pre-allocate port for relay_b so we can include it in the announcement
37 let relay_b = TestRelay::start_with_sync(Some(relay_a.url().into())).await; 37 let relay_b_port = TestRelay::find_free_port();
38 println!( 38 let relay_b_domain = format!("127.0.0.1:{}", relay_b_port);
39 "relay_b started at {} (domain: {})", 39 println!("Pre-allocated relay_b domain: {}", relay_b_domain);
40 relay_b.url(),
41 relay_b.domain()
42 );
43 40
44 // 3. Create test keys 41 // 3. Create test keys
45 let keys = Keys::generate(); 42 let keys = Keys::generate();
46 43
47 // 4. Wait for relay_b's sync connection to establish 44 // 4. Create a repository announcement that lists BOTH relays
48 tokio::time::sleep(Duration::from_secs(1)).await; 45 // This is required because relay_b's write policy checks that events reference its domain
49
50 // 5. Create a repository announcement that lists BOTH relays
51 // This is required for sync - the event must reference both relays
52 // for the write policy to accept it on both sides
53 let announcement = create_repo_announcement( 46 let announcement = create_repo_announcement(
54 &keys, 47 &keys,
55 &[&relay_a.domain(), &relay_b.domain()], 48 &[&relay_a.domain(), &relay_b_domain],
56 "test-repo-bootstrap", 49 "test-repo-bootstrap",
57 ); 50 );
58 let announcement_id = announcement.id; 51 let announcement_id = announcement.id;
@@ -66,7 +59,8 @@ async fn test_bootstrap_syncs_existing_layer2_events() {
66 println!(" Tag: {:?}", tag.as_slice()); 59 println!(" Tag: {:?}", tag.as_slice());
67 } 60 }
68 61
69 // 6. Send announcement to relay_a 62 // 5. Send announcement to relay_a BEFORE relay_b starts
63 // This is key for testing bootstrap sync
70 let client_a = TestClient::new(relay_a.url(), keys.clone()) 64 let client_a = TestClient::new(relay_a.url(), keys.clone())
71 .await 65 .await
72 .expect("Failed to connect to relay_a"); 66 .expect("Failed to connect to relay_a");
@@ -79,17 +73,35 @@ async fn test_bootstrap_syncs_existing_layer2_events() {
79 73
80 client_a.disconnect().await; 74 client_a.disconnect().await;
81 75
82 // 7. Wait for sync to occur 76 // 6. Wait briefly to ensure event is persisted on relay_a
83 tokio::time::sleep(Duration::from_secs(2)).await; 77 tokio::time::sleep(Duration::from_millis(500)).await;
84 78
85 // 8. Verify announcement synced to relay_b 79 // 7. NOW start relay_b on the pre-allocated port, configured to sync from relay_a
80 // The announcement already exists on relay_a, so this tests bootstrap sync
81 let relay_b = TestRelay::start_on_port_with_options(
82 relay_b_port,
83 Some(relay_a.url().into()),
84 false,
85 )
86 .await;
87 println!(
88 "relay_b started at {} (domain: {})",
89 relay_b.url(),
90 relay_b.domain()
91 );
92
93 // 8. Wait for bootstrap sync to complete
94 // Bootstrap sync should happen automatically on startup
95 tokio::time::sleep(Duration::from_secs(3)).await;
96
97 // 9. Verify announcement synced to relay_b
86 let filter = Filter::new() 98 let filter = Filter::new()
87 .kind(Kind::Custom(KIND_REPOSITORY_STATE)) 99 .kind(Kind::Custom(KIND_REPOSITORY_STATE))
88 .author(keys.public_key()); 100 .author(keys.public_key());
89 101
90 let synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await; 102 let synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await;
91 103
92 // 9. Cleanup 104 // 10. Cleanup
93 relay_b.stop().await; 105 relay_b.stop().await;
94 relay_a.stop().await; 106 relay_a.stop().await;
95 107
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() {
412async fn test_live_sync_event_count() { 412async fn test_live_sync_event_count() {
413 let mut harness = MetricsTestHarness::with_sources(1).await; 413 let mut harness = MetricsTestHarness::with_sources(1).await;
414 414
415 // Start syncing BEFORE adding events 415 // Pre-allocate syncing relay port to include in announcements
416 harness.start_syncing_relay(0).await; 416 let sync_port = TestRelay::find_free_port();
417 let sync_domain = format!("127.0.0.1:{}", sync_port);
418
419 // Start syncing relay with pre-allocated port
420 harness.start_syncing_relay_on_port(0, sync_port).await;
417 tokio::time::sleep(Duration::from_secs(2)).await; 421 tokio::time::sleep(Duration::from_secs(2)).await;
418 422
419 // Now add events - these should be "live" not "startup" 423 // Now add events - these should be "live" not "startup"
424 // Include BOTH domains so events are accepted by both relays
420 let keys = Keys::generate(); 425 let keys = Keys::generate();
421 let events: Vec<_> = (0..2) 426 let events: Vec<_> = (0..2)
422 .map(|i| { 427 .map(|i| {
423 create_repo_announcement(&keys, &[&harness.source_domain(0)], &format!("live-{}", i)) 428 create_repo_announcement(
429 &keys,
430 &[&harness.source_domain(0), &sync_domain],
431 &format!("live-{}", i),
432 )
424 }) 433 })
425 .collect(); 434 .collect();
426 harness.submit_events(0, &events).await.unwrap(); 435 harness.submit_events(0, &events).await.unwrap();
427 436
428 tokio::time::sleep(Duration::from_secs(2)).await; 437 // Wait longer for live events to be processed and metrics updated
438 tokio::time::sleep(Duration::from_secs(4)).await;
429 let metrics = harness.get_metrics().await.unwrap(); 439 let metrics = harness.get_metrics().await.unwrap();
430 440
431 let live_count = metrics.events_total("live"); 441 let live_count = metrics.events_total("live");
@@ -532,7 +542,25 @@ async fn test_multi_source_aggregate_counts() {
532 // Note: Current impl only supports ONE sync source, so this tests 542 // Note: Current impl only supports ONE sync source, so this tests
533 // that with one source, tracked=1 and connected=1 543 // that with one source, tracked=1 and connected=1
534 let mut harness = MetricsTestHarness::with_sources(1).await; 544 let mut harness = MetricsTestHarness::with_sources(1).await;
535 harness.start_syncing_relay(0).await; 545
546 // Pre-allocate syncing relay port and create an announcement that includes both domains
547 let sync_port = TestRelay::find_free_port();
548 let sync_domain = format!("127.0.0.1:{}", sync_port);
549
550 // Create announcement on source that references both relays
551 let keys = Keys::generate();
552 let announcement = create_repo_announcement(
553 &keys,
554 &[&harness.source_domain(0), &sync_domain],
555 "test-repo",
556 );
557 harness
558 .submit_events(0, &[announcement])
559 .await
560 .unwrap();
561
562 // Now start syncing relay - it should sync the existing announcement
563 harness.start_syncing_relay_on_port(0, sync_port).await;
536 tokio::time::sleep(Duration::from_secs(2)).await; 564 tokio::time::sleep(Duration::from_secs(2)).await;
537 565
538 let metrics = harness.get_metrics().await.unwrap(); 566 let metrics = harness.get_metrics().await.unwrap();
@@ -553,7 +581,8 @@ async fn test_multi_source_aggregate_counts() {
553 581
554 // Stop source, verify connected drops to 0 582 // Stop source, verify connected drops to 0
555 harness.stop_source(0).await; 583 harness.stop_source(0).await;
556 tokio::time::sleep(Duration::from_secs(2)).await; 584 // Wait longer for disconnect to be detected and metrics updated
585 tokio::time::sleep(Duration::from_secs(4)).await;
557 586
558 let metrics = harness.get_metrics().await.unwrap(); 587 let metrics = harness.get_metrics().await.unwrap();
559 588