From c82684092c7b4f81e49833b0888500fcb9851218 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 11:19:38 +0000 Subject: fix(sync): improve metrics recording and connection failure detection Changes: - Fix connection attempt metrics: record success/failure based on actual connection result instead of pre-emptively recording failure - Add health tracker integration on connection failure: call record_failure() and record_health_state() in error path - Add connection verification in relay_connection.rs: wait 500ms after connect() then verify is_connected() to detect silent failures - Add configurable disconnect check interval via NGIT_SYNC_DISCONNECT_CHECK_INTERVAL_SECS env var - Update TestRelay with fast test settings: startup_delay=0, jitter=0, disconnect_check_interval=1s - Add debug output to metrics tests for investigation Note: Tests may still fail due to 5-second base backoff in health tracker. A follow-up task will add NGIT_SYNC_BASE_BACKOFF_SECS config parameter to allow faster test cycles. Related: metrics-wiring-plan.md Tasks 1 & 2 --- tests/sync/metrics.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'tests/sync') diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 82d681e..e11fe58 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs @@ -368,17 +368,48 @@ async fn test_startup_sync_event_count() { /// NOTE: This test may fail until sync metrics recording is fully wired up. /// The test documents the expected behavior. #[tokio::test] -#[ignore] // Enable when metrics recording is implemented async fn test_connection_failure_increments_counter() { let mut harness = MetricsTestHarness::with_sources(0).await; // No sources harness.start_syncing_relay_to_nowhere().await; // Wait for initial connection attempts tokio::time::sleep(Duration::from_secs(2)).await; + + // Fetch raw metrics to debug + let syncing_url = harness.syncing_relay_url().expect("Syncing relay should be started"); + let raw_1 = fetch_metrics(syncing_url) + .await + .expect("Failed to fetch metrics"); + + // Print all sync-related metrics + println!("\n=== RAW METRICS (t1) ==="); + for line in raw_1.lines() { + if line.contains("sync") || line.contains("connection") { + println!("{}", line); + } + } + println!("========================\n"); + let metrics_1 = harness.get_metrics().await.unwrap(); // Wait for more attempts tokio::time::sleep(Duration::from_secs(2)).await; + + // Fetch raw metrics again + let syncing_url = harness.syncing_relay_url().expect("Syncing relay should be started"); + let raw_2 = fetch_metrics(syncing_url) + .await + .expect("Failed to fetch metrics"); + + // Print all sync-related metrics + println!("\n=== RAW METRICS (t2) ==="); + for line in raw_2.lines() { + if line.contains("sync") || line.contains("connection") { + println!("{}", line); + } + } + println!("========================\n"); + let metrics_2 = harness.get_metrics().await.unwrap(); // Failure counter should have increased @@ -496,7 +527,6 @@ async fn test_relay_connected_status() { /// NOTE: This test may fail until sync metrics recording is fully wired up. /// The test documents the expected behavior. #[tokio::test] -#[ignore] // Ignored until sync metrics are fully wired up async fn test_health_state_degrades_on_failure() { use crate::common::sync_helpers::MetricsTestHarness; -- cgit v1.2.3