diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-22 21:03:49 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-22 21:03:49 +0000 |
| commit | 6b55efedba7c069eff7a3e335845a961d40274db (patch) | |
| tree | 7e036869007cb503fda5a81d959ecd49a9b3e5a3 /tests/common/sync_helpers.rs | |
| parent | 1df90c609399c675e629b97294aee81a0b1e66dd (diff) | |
chore: cargo fmt and clippy
Diffstat (limited to 'tests/common/sync_helpers.rs')
| -rw-r--r-- | tests/common/sync_helpers.rs | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index cccfbdd..8279a04 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs | |||
| @@ -795,9 +795,8 @@ impl MetricsTestHarness { | |||
| 795 | /// Start syncing relay on a specific port pointing to source[idx] | 795 | /// Start syncing relay on a specific port pointing to source[idx] |
| 796 | pub async fn start_syncing_relay_on_port(&mut self, source_idx: usize, port: u16) { | 796 | pub async fn start_syncing_relay_on_port(&mut self, source_idx: usize, port: u16) { |
| 797 | let source_url = self.source_relays[source_idx].url().to_string(); | 797 | let source_url = self.source_relays[source_idx].url().to_string(); |
| 798 | self.syncing_relay = Some( | 798 | self.syncing_relay = |
| 799 | TestRelay::start_on_port_with_options(port, Some(source_url), false).await, | 799 | Some(TestRelay::start_on_port_with_options(port, Some(source_url), false).await); |
| 800 | ); | ||
| 801 | } | 800 | } |
| 802 | 801 | ||
| 803 | /// Start syncing relay pointing to random unused port (for failure tests) | 802 | /// Start syncing relay pointing to random unused port (for failure tests) |
| @@ -1122,16 +1121,15 @@ async fn send_to_relay(relay: &TestRelay, event: &Event) -> Result<(), String> { | |||
| 1122 | /// let result = run_sync_test(&[], &[comment]).await; | 1121 | /// let result = run_sync_test(&[], &[comment]).await; |
| 1123 | /// // Assert comment synced to result.syncing_relay | 1122 | /// // Assert comment synced to result.syncing_relay |
| 1124 | /// ``` | 1123 | /// ``` |
| 1125 | pub async fn run_sync_test( | 1124 | pub async fn run_sync_test(historic_events: &[Event], live_events: &[Event]) -> SyncTestResult { |
| 1126 | historic_events: &[Event], | ||
| 1127 | live_events: &[Event], | ||
| 1128 | ) -> SyncTestResult { | ||
| 1129 | // Validate usage - cannot provide events in both slices | 1125 | // Validate usage - cannot provide events in both slices |
| 1130 | let historic_mode = !historic_events.is_empty(); | 1126 | let historic_mode = !historic_events.is_empty(); |
| 1131 | let live_mode = !live_events.is_empty(); | 1127 | let live_mode = !live_events.is_empty(); |
| 1132 | 1128 | ||
| 1133 | if historic_mode && live_mode { | 1129 | if historic_mode && live_mode { |
| 1134 | panic!("Invalid usage: both historic_events and live_events provided. Use one or the other."); | 1130 | panic!( |
| 1131 | "Invalid usage: both historic_events and live_events provided. Use one or the other." | ||
| 1132 | ); | ||
| 1135 | } | 1133 | } |
| 1136 | // Note: Both slices can be empty - this tests just the announcement sync | 1134 | // Note: Both slices can be empty - this tests just the announcement sync |
| 1137 | 1135 | ||
| @@ -1144,11 +1142,8 @@ pub async fn run_sync_test( | |||
| 1144 | 1142 | ||
| 1145 | // 3. Create keys and announcement listing both relays | 1143 | // 3. Create keys and announcement listing both relays |
| 1146 | let keys = Keys::generate(); | 1144 | let keys = Keys::generate(); |
| 1147 | let announcement = create_repo_announcement( | 1145 | let announcement = |
| 1148 | &keys, | 1146 | create_repo_announcement(&keys, &[&source.domain(), &syncing_domain], "test-repo"); |
| 1149 | &[&source.domain(), &syncing_domain], | ||
| 1150 | "test-repo", | ||
| 1151 | ); | ||
| 1152 | 1147 | ||
| 1153 | // 4. Send announcement + historic events to source BEFORE syncing relay starts | 1148 | // 4. Send announcement + historic events to source BEFORE syncing relay starts |
| 1154 | send_to_relay(&source, &announcement) | 1149 | send_to_relay(&source, &announcement) |
| @@ -1161,12 +1156,8 @@ pub async fn run_sync_test( | |||
| 1161 | } | 1156 | } |
| 1162 | 1157 | ||
| 1163 | // 5. Start syncing relay (connects to source) | 1158 | // 5. Start syncing relay (connects to source) |
| 1164 | let syncing = TestRelay::start_on_port_with_options( | 1159 | let syncing = |
| 1165 | syncing_port, | 1160 | TestRelay::start_on_port_with_options(syncing_port, Some(source.url().into()), false).await; |
| 1166 | Some(source.url().into()), | ||
| 1167 | false, | ||
| 1168 | ) | ||
| 1169 | .await; | ||
| 1170 | 1161 | ||
| 1171 | // 6. Wait for sync connection to establish | 1162 | // 6. Wait for sync connection to establish |
| 1172 | let _ = wait_for_sync_connection(syncing.url(), 1, Duration::from_secs(5)).await; | 1163 | let _ = wait_for_sync_connection(syncing.url(), 1, Duration::from_secs(5)).await; |
| @@ -1208,8 +1199,8 @@ mod sync_helper_tests { | |||
| 1208 | async fn test_run_sync_test_panics_with_both_slices() { | 1199 | async fn test_run_sync_test_panics_with_both_slices() { |
| 1209 | let keys = Keys::generate(); | 1200 | let keys = Keys::generate(); |
| 1210 | let coord = repo_coord(&keys, "test"); | 1201 | let coord = repo_coord(&keys, "test"); |
| 1211 | let historic = build_layer2_issue_event(&keys, &coord, "Historic") | 1202 | let historic = |
| 1212 | .expect("Should create event"); | 1203 | build_layer2_issue_event(&keys, &coord, "Historic").expect("Should create event"); |
| 1213 | let live = build_layer3_reply_with_e_tag(&keys, &EventId::all_zeros(), "Live") | 1204 | let live = build_layer3_reply_with_e_tag(&keys, &EventId::all_zeros(), "Live") |
| 1214 | .expect("Should create event"); | 1205 | .expect("Should create event"); |
| 1215 | 1206 | ||