From 7146ee550944c71a4e48018a34820ce9a9d99f95 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 13:09:39 +0000 Subject: fix: classify sync events as startup/live based on EOSE, not relay type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, events were classified as 'startup' or 'live' based on whether they came from a bootstrap relay (is_bootstrap flag). This meant ALL events from bootstrap relays were counted as 'startup', even events received after the initial sync completed. Now events are classified based on whether EOSE (End Of Stored Events) has been received for that connection: - Events BEFORE EOSE → 'startup' (historical events during initial sync) - Events AFTER EOSE → 'live' (new events via real-time subscription) This enables the test_live_sync_event_count test which validates that events received after sync connection is established are counted as live events. Also removed the #[ignore] attribute from test_live_sync_event_count since the metrics are now properly wired up. --- src/sync/mod.rs | 12 ++++++++---- tests/sync/metrics.rs | 6 ------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 15c89e3..b6cd00a 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1249,19 +1249,21 @@ impl SyncManager { // Spawn event processor let relay_url_clone = relay_url.clone(); let metrics_clone = self.metrics.clone(); // Clone metrics for the spawned task - let is_bootstrap_clone = is_bootstrap; // Clone is_bootstrap for the spawned task tokio::spawn(async move { // Track whether we've already sent a disconnect notification let mut disconnect_sent = false; + // Track whether EOSE has been received - events before EOSE are "startup", after are "live" + let mut eose_received = false; while let Some(relay_event) = event_rx.recv().await { match relay_event { RelayEvent::Event(event) => { if let Some(ref metrics) = metrics_clone { - let source = if is_bootstrap_clone { - event_source::STARTUP - } else { + // Events before EOSE are "startup", events after EOSE are "live" + let source = if eose_received { event_source::LIVE + } else { + event_source::STARTUP }; metrics.record_event(source); } @@ -1275,6 +1277,8 @@ impl SyncManager { .await; } RelayEvent::EndOfStoredEvents(sub_id) => { + // Mark EOSE as received - subsequent events are "live" + eose_received = true; tracing::debug!( relay = %relay_url_clone, sub_id = %sub_id, diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 3accd0f..98ce4f3 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs @@ -410,11 +410,7 @@ async fn test_connection_failure_increments_counter() { /// This test validates that events received via live subscription /// (after sync connection is established) are counted separately /// from startup/bootstrap events. -/// -/// NOTE: This test may fail until sync metrics recording is fully wired up. -/// The test documents the expected behavior. #[tokio::test] -#[ignore] // Enable when live event sync metrics are wired up async fn test_live_sync_event_count() { let mut harness = MetricsTestHarness::with_sources(1).await; @@ -437,8 +433,6 @@ async fn test_live_sync_event_count() { let live_count = metrics.events_total("live"); println!("Live events synced: {:?}", live_count); - // NOTE: This will likely fail until sync metrics are wired up - // Test documents the expectation assert_eq!(live_count, Some(2), "Should have 2 live events"); harness.stop_all().await; -- cgit v1.2.3