From e3e0cfd3a53b9509eb4292766d5eac4292faa4ee Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 12 Aug 2026 15:34:02 +0000 Subject: [PATCH] test(sync): wait for full live coverage before metric delivery A connected source socket and a fixed delay do not prove that purgatory promotion has installed full-repository filters. The live-event metric test could publish both patches during state-only coverage and correctly observe no live sync increments. Wait with a bounded deadline for the full-repository AddFilters generation to complete its core live extension before publishing. This keeps the metric assertion tied specifically to live delivery. Validated with the focused live sync event-count integration test. --- tests/common/sync_helpers.rs | 18 ++++++++++++++++++ tests/sync/metrics.rs | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index dbd3aca..668b5fc 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs @@ -45,6 +45,24 @@ pub async fn wait_for_new_descendant_live_generation( } } +pub async fn wait_for_full_repo_live_coverage(relay: &TestRelay, timeout: Duration) { + let deadline = tokio::time::Instant::now() + timeout; + loop { + let log = std::fs::read_to_string(relay.log_path()).unwrap_or_default(); + let installed = log + .rfind("new_full_repos=1") + .is_some_and(|offset| log[offset..].contains("Extended core live coverage")); + if installed { + return; + } + assert!( + tokio::time::Instant::now() < deadline, + "full-repository live coverage was not installed before the deadline" + ); + tokio::task::yield_now().await; + } +} + // NOTE: Using rust-nostr Kind variants: // - Kind::GitIssue.as_u16() -> Kind::GitIssue (1621) // - Kind::Comment.as_u16() -> Kind::Comment (1111) diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 1b79413..9c60bff 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs @@ -18,7 +18,8 @@ use crate::common::{ port, sync_helpers::{ create_repo_announcement, fetch_metrics, setup_announcement_on_relay, - wait_for_sync_connection, MetricsTestHarness, ParsedMetrics, TestClient, + wait_for_full_repo_live_coverage, wait_for_sync_connection, MetricsTestHarness, + ParsedMetrics, TestClient, }, TestRelay, }; @@ -433,8 +434,7 @@ async fn test_live_sync_event_count() { .await .expect("Sync connection should be established"); - // Additional delay to ensure purgatory promotion completes on syncing relay - tokio::time::sleep(Duration::from_secs(4)).await; + wait_for_full_repo_live_coverage(&syncing_relay, Duration::from_secs(20)).await; // Now add Layer 2 patch events (not announcements) - these are accepted immediately // (Layer 2 events are accepted directly to DB, no purgatory)