diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 17:03:40 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 17:03:40 +0000 |
| commit | b167f1b2ae7edbcab95554b5203d22d9e372c8b5 (patch) | |
| tree | 39b3bb879302cb6a4eaabded4a5d20f7d0d68ffc /tests/common | |
| parent | fdbc8895e1e9e712882bd854908295a95e7afcb9 (diff) | |
feat(sync): Phase 1 MVP - single relay proactive sync
- Add src/sync/ module with SyncManager
- Add NGIT_SYNC_RELAY_URL config option
- Subscribe to kind 30617 on configured relay
- Validate synced events through Nip34WritePolicy
- Integration test with two TestRelay instances
Diffstat (limited to 'tests/common')
| -rw-r--r-- | tests/common/relay.rs | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/tests/common/relay.rs b/tests/common/relay.rs index 449b4cb..9fb7b1d 100644 --- a/tests/common/relay.rs +++ b/tests/common/relay.rs | |||
| @@ -33,11 +33,36 @@ impl TestRelay { | |||
| 33 | /// } | 33 | /// } |
| 34 | /// ``` | 34 | /// ``` |
| 35 | pub async fn start() -> Self { | 35 | pub async fn start() -> Self { |
| 36 | Self::start_with_port(Self::find_free_port()).await | 36 | Self::start_with_options(Self::find_free_port(), None).await |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /// Start relay on a specific port | 39 | /// Start relay on a specific port |
| 40 | pub async fn start_with_port(port: u16) -> Self { | 40 | pub async fn start_with_port(port: u16) -> Self { |
| 41 | Self::start_with_options(port, None).await | ||
| 42 | } | ||
| 43 | |||
| 44 | /// Start relay with sync from another relay | ||
| 45 | /// | ||
| 46 | /// # Example | ||
| 47 | /// | ||
| 48 | /// ```no_run | ||
| 49 | /// use common::TestRelay; | ||
| 50 | /// | ||
| 51 | /// #[tokio::test] | ||
| 52 | /// async fn test_sync() { | ||
| 53 | /// let source = TestRelay::start().await; | ||
| 54 | /// let syncing = TestRelay::start_with_sync(source.url()).await; | ||
| 55 | /// // ... test sync behavior ... | ||
| 56 | /// syncing.stop().await; | ||
| 57 | /// source.stop().await; | ||
| 58 | /// } | ||
| 59 | /// ``` | ||
| 60 | pub async fn start_with_sync(sync_relay_url: &str) -> Self { | ||
| 61 | Self::start_with_options(Self::find_free_port(), Some(sync_relay_url.to_string())).await | ||
| 62 | } | ||
| 63 | |||
| 64 | /// Start relay with options | ||
| 65 | async fn start_with_options(port: u16, sync_relay_url: Option<String>) -> Self { | ||
| 41 | let bind_address = format!("127.0.0.1:{}", port); | 66 | let bind_address = format!("127.0.0.1:{}", port); |
| 42 | let url = format!("ws://127.0.0.1:{}", port); | 67 | let url = format!("ws://127.0.0.1:{}", port); |
| 43 | 68 | ||
| @@ -62,16 +87,21 @@ impl TestRelay { | |||
| 62 | .expect("Failed to generate test npub"); | 87 | .expect("Failed to generate test npub"); |
| 63 | 88 | ||
| 64 | // Start the relay process | 89 | // Start the relay process |
| 65 | let process = Command::new(&binary_path) | 90 | let mut cmd = Command::new(&binary_path); |
| 66 | .env("NGIT_BIND_ADDRESS", &bind_address) | 91 | cmd.env("NGIT_BIND_ADDRESS", &bind_address) |
| 67 | .env("NGIT_DOMAIN", &bind_address) // Set domain to match bind address | 92 | .env("NGIT_DOMAIN", &bind_address) // Set domain to match bind address |
| 68 | .env("NGIT_GIT_DATA_PATH", git_data_dir.path()) | 93 | .env("NGIT_GIT_DATA_PATH", git_data_dir.path()) |
| 69 | .env("NGIT_OWNER_NPUB", &test_npub) | 94 | .env("NGIT_OWNER_NPUB", &test_npub) |
| 70 | .env("RUST_LOG", "warn") // Less logging during tests | 95 | .env("RUST_LOG", "warn") // Less logging during tests |
| 71 | .stdout(Stdio::null()) | 96 | .stdout(Stdio::null()) |
| 72 | .stderr(Stdio::null()) | 97 | .stderr(Stdio::null()); |
| 73 | .spawn() | 98 | |
| 74 | .expect("Failed to start relay process"); | 99 | // Add sync relay URL if provided |
| 100 | if let Some(ref sync_url) = sync_relay_url { | ||
| 101 | cmd.env("NGIT_SYNC_RELAY_URL", sync_url); | ||
| 102 | } | ||
| 103 | |||
| 104 | let process = cmd.spawn().expect("Failed to start relay process"); | ||
| 75 | 105 | ||
| 76 | let relay = Self { process, url, port }; | 106 | let relay = Self { process, url, port }; |
| 77 | 107 | ||