upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/common/sync_helpers.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 17:07:30 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 17:07:30 +0000
commitd7ea44d5b594763116175325be06c1125983490a (patch)
tree8be8c8a79d2a05457bd3a573a2b32aa00be9b79e /tests/common/sync_helpers.rs
parentc93ffaf30ae43cdaf1cf59684318970beca65979 (diff)
refactor: migrate historic_sync.rs tests to use run_sync_test() helper
- Refactored all 4 tests in historic_sync.rs to use run_sync_test() - Tests maintain same logic and assertions, only setup simplified - Moved run_sync_test() and SyncTestResult outside #[cfg(test)] module - Updated validation to allow empty event slices (for announcement-only tests) - All 4 historic_sync tests passing (test_bootstrap_syncs_existing_layer2_events, test_relay_replays_events_after_restart, test_announcement_not_listing_relay_is_not_synced, test_history_sync_without_negentropy) - Result: 39/40 tests passing (1 more than Phase 1 baseline of 38/40)
Diffstat (limited to 'tests/common/sync_helpers.rs')
-rw-r--r--tests/common/sync_helpers.rs15
1 files changed, 4 insertions, 11 deletions
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs
index 67dec3c..8971369 100644
--- a/tests/common/sync_helpers.rs
+++ b/tests/common/sync_helpers.rs
@@ -1060,6 +1060,7 @@ mod tests {
1060 let metrics = ParsedMetrics::parse(text); 1060 let metrics = ParsedMetrics::parse(text);
1061 assert_eq!(metrics.relay_connected("ws://127.0.0.1:12345"), Some(true)); 1061 assert_eq!(metrics.relay_connected("ws://127.0.0.1:12345"), Some(true));
1062 } 1062 }
1063}
1063 1064
1064// ============================================================================ 1065// ============================================================================
1065// Unified Sync Test Helper 1066// Unified Sync Test Helper
@@ -1125,16 +1126,14 @@ pub async fn run_sync_test(
1125 historic_events: &[Event], 1126 historic_events: &[Event],
1126 live_events: &[Event], 1127 live_events: &[Event],
1127) -> SyncTestResult { 1128) -> SyncTestResult {
1128 // Validate usage - exactly one slice must have content 1129 // Validate usage - cannot provide events in both slices
1129 let historic_mode = !historic_events.is_empty(); 1130 let historic_mode = !historic_events.is_empty();
1130 let live_mode = !live_events.is_empty(); 1131 let live_mode = !live_events.is_empty();
1131 1132
1132 if historic_mode && live_mode { 1133 if historic_mode && live_mode {
1133 panic!("Invalid usage: both historic_events and live_events provided. Use one or the other."); 1134 panic!("Invalid usage: both historic_events and live_events provided. Use one or the other.");
1134 } 1135 }
1135 if !historic_mode && !live_mode { 1136 // Note: Both slices can be empty - this tests just the announcement sync
1136 panic!("Invalid usage: both historic_events and live_events are empty. Provide at least one.");
1137 }
1138 1137
1139 // 1. Pre-allocate syncing relay port for announcement tags 1138 // 1. Pre-allocate syncing relay port for announcement tags
1140 let syncing_port = TestRelay::find_free_port(); 1139 let syncing_port = TestRelay::find_free_port();
@@ -1218,11 +1217,5 @@ mod sync_helper_tests {
1218 let _result = run_sync_test(&[historic], &[live]).await; 1217 let _result = run_sync_test(&[historic], &[live]).await;
1219 } 1218 }
1220 1219
1221 #[tokio::test] 1220 // Note: Empty slices are now allowed - tests just the announcement sync
1222 #[should_panic(expected = "both historic_events and live_events are empty")]
1223 async fn test_run_sync_test_panics_with_empty_slices() {
1224 // Should panic - both slices empty
1225 let _result = run_sync_test(&[], &[]).await;
1226 }
1227}
1228} 1221}