diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-18 16:46:53 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-18 16:46:53 +0000 |
| commit | 6ad7136027c56c3a523278d90ade3da018e39273 (patch) | |
| tree | dad50501b2085c320a9316e17928b584cc8ec80b /tests/sync/bootstrap.rs | |
| parent | 11a656fa96d6f60e2d8e8fd31657e24d6cc7cf21 (diff) | |
sync: turn off negentropy and fix some tests
Diffstat (limited to 'tests/sync/bootstrap.rs')
| -rw-r--r-- | tests/sync/bootstrap.rs | 50 |
1 files changed, 31 insertions, 19 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 | ||