upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/sync/mod.rs114
1 files changed, 108 insertions, 6 deletions
diff --git a/tests/sync/mod.rs b/tests/sync/mod.rs
index ffda73e..58b7354 100644
--- a/tests/sync/mod.rs
+++ b/tests/sync/mod.rs
@@ -3,7 +3,7 @@
3//! This module organizes tests for ngit-grasp's proactive sync functionality. 3//! This module organizes tests for ngit-grasp's proactive sync functionality.
4//! Tests are grouped by sync scenario: 4//! Tests are grouped by sync scenario:
5//! 5//!
6//! - Bootstrap sync (relay syncs from pre-configured bootstrap relay) 6//! - Historic sync (relay syncs from pre-configured bootstrap relay)
7//! - Relay discovery (relay discovers other relays from announcement events) 7//! - Relay discovery (relay discovers other relays from announcement events)
8//! - Live sync (events sync in real-time after connection established) 8//! - Live sync (events sync in real-time after connection established)
9//! - Tag variations (testing different Layer 2/3 tag types: a/A/q, e/E/q) 9//! - Tag variations (testing different Layer 2/3 tag types: a/A/q, e/E/q)
@@ -12,17 +12,119 @@
12//! 12//!
13//! # Test Files 13//! # Test Files
14//! 14//!
15//! - `bootstrap.rs` - Tests 1, 4: sync from bootstrap relay 15//! - `historic_sync.rs` - Bootstrap and replay tests (uses `run_sync_test()` helper)
16//! - `discovery.rs` - Tests 2, 3: relay discovery from announcements 16//! - `discovery.rs` - Relay discovery from announcements (manual setup required)
17//! - `live_sync.rs` - Tests 5, 6, 7: real-time sync after connection 17//! - `live_sync.rs` - Real-time sync after connection (manual setup required)
18//! - `tag_variations.rs` - Tests 8, 9: Layer 2/3 tag type coverage 18//! - `tag_variations.rs` - Layer 2/3 tag type coverage (manual setup required)
19//! - `catchup.rs` - Test 0: catchup after disconnect (stub, `#[ignore]`) 19//! - `catchup.rs` - Catchup after disconnect (stub, `#[ignore]`)
20//! - `metrics.rs` - Prometheus metrics integration tests 20//! - `metrics.rs` - Prometheus metrics integration tests
21//! 21//!
22//! # Test Patterns
23//!
24//! This module uses two main testing approaches, each suited to different scenarios:
25//!
26//! ## Pattern 1: Helper-Based Tests (Historic Sync)
27//!
28//! **Use `run_sync_test()` for:**
29//! - Verifying historic event sync (events published before relay starts)
30//! - Bootstrap and initialization tests
31//! - Simple count-based event verification
32//! - Single-relay scenarios
33//!
34//! **Example from `historic_sync.rs`:**
35//! ```rust
36//! use common::sync_helpers::{run_sync_test, build_layer2_issue_event};
37//!
38//! #[tokio::test]
39//! async fn test_bootstrap_syncs_existing_layer2_events() {
40//! let repo_event = /* create repo announcement */;
41//! let issue1 = build_layer2_issue_event(&repo_event, "Issue 1");
42//! let issue2 = build_layer2_issue_event(&repo_event, "Issue 2");
43//!
44//! run_sync_test(
45//! &[&repo_event], // Bootstrap events
46//! &[&issue1, &issue2], // Events to verify
47//! 2, // Expected count
48//! ).await;
49//! }
50//! ```
51//!
52//! **Helper Architecture:**
53//! - Publishes all events to bootstrap relay before target relay starts
54//! - Automatically starts target relay with bootstrap relay configured
55//! - Verifies event counts after sync completes
56//! - Handles all relay lifecycle management
57//!
58//! ## Pattern 2: Manual Setup Tests (Live, Discovery, Tag Variations)
59//!
60//! **Use manual setup for:**
61//! - Live sync (events published *during* relay operation)
62//! - Multi-relay coordination (discovery chains)
63//! - Detailed event inspection (tag format verification)
64//! - Precise timing control
65//!
66//! **Example from `live_sync.rs`:**
67//! ```rust
68//! #[tokio::test]
69//! async fn test_live_sync_layer2_events() {
70//! let bootstrap = TestRelay::start().await;
71//! let target = TestRelay::start_with_bootstrap(bootstrap.url()).await;
72//!
73//! // Publish AFTER relay is running (live sync)
74//! let event = build_layer2_issue_event(&repo, "Live Issue");
75//! client.publish_event(event).await;
76//!
77//! // Verify with timing control
78//! wait_for_event_on_relay(&target, &event.id, timeout).await;
79//! }
80//! ```
81//!
82//! **Example from `discovery.rs`:**
83//! ```rust
84//! #[tokio::test]
85//! async fn test_recursive_relay_discovery() {
86//! // Multi-relay orchestration
87//! let relay1 = TestRelay::start().await;
88//! let relay2 = TestRelay::start().await;
89//! let relay3 = TestRelay::start().await;
90//!
91//! // relay1 announces relay2, relay2 announces relay3
92//! // Verify relay1 discovers relay3 through chain
93//! }
94//! ```
95//!
96//! **Example from `tag_variations.rs`:**
97//! ```rust
98//! #[tokio::test]
99//! async fn test_layer2_sync_with_uppercase_a_tag() {
100//! // Detailed tag format verification
101//! let event = build_event_with_uppercase_A();
102//!
103//! // Custom assertions about tag normalization
104//! assert!(synced_event.tags.contains_uppercase_a());
105//! }
106//! ```
107//!
108//! ## Why Two Patterns?
109//!
110//! The `run_sync_test()` helper embodies a specific pattern:
111//! ```
112//! Setup → Publish Batch → Start Relay → Verify Counts
113//! ```
114//!
115//! This pattern is **incompatible** with tests needing:
116//! - Event publication *during* relay operation (live sync)
117//! - Multiple relay coordination (discovery)
118//! - Detailed event inspection beyond counts (tag variations)
119//! - Precise timing control
120//!
121//! For these scenarios, manual setup provides necessary flexibility.
122//!
22//! # Shared Imports 123//! # Shared Imports
23//! 124//!
24//! All sync tests use helpers from `common::sync_helpers`: 125//! All sync tests use helpers from `common::sync_helpers`:
25//! - `TestClient` - Client with retry logic 126//! - `TestClient` - Client with retry logic
127//! - `run_sync_test()` - Helper for historic sync tests
26//! - Event builders for Layer 2/3 events 128//! - Event builders for Layer 2/3 events
27//! - `wait_for_event_on_relay()` - Non-panicking assertion helper 129//! - `wait_for_event_on_relay()` - Non-panicking assertion helper
28//! - `fetch_metrics()` - Prometheus metrics fetching 130//! - `fetch_metrics()` - Prometheus metrics fetching