diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 11:19:38 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 11:19:38 +0000 |
| commit | c82684092c7b4f81e49833b0888500fcb9851218 (patch) | |
| tree | 6853940a5bb975aa17e1f91be988e3b3303ff39f /tests/sync | |
| parent | 532a7d0d5d8461bad0fc799aacb5eea0135f79f3 (diff) | |
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
Diffstat (limited to 'tests/sync')
| -rw-r--r-- | tests/sync/metrics.rs | 34 |
1 files changed, 32 insertions, 2 deletions
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() { | |||
| 368 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | 368 | /// NOTE: This test may fail until sync metrics recording is fully wired up. |
| 369 | /// The test documents the expected behavior. | 369 | /// The test documents the expected behavior. |
| 370 | #[tokio::test] | 370 | #[tokio::test] |
| 371 | #[ignore] // Enable when metrics recording is implemented | ||
| 372 | async fn test_connection_failure_increments_counter() { | 371 | async fn test_connection_failure_increments_counter() { |
| 373 | let mut harness = MetricsTestHarness::with_sources(0).await; // No sources | 372 | let mut harness = MetricsTestHarness::with_sources(0).await; // No sources |
| 374 | harness.start_syncing_relay_to_nowhere().await; | 373 | harness.start_syncing_relay_to_nowhere().await; |
| 375 | 374 | ||
| 376 | // Wait for initial connection attempts | 375 | // Wait for initial connection attempts |
| 377 | tokio::time::sleep(Duration::from_secs(2)).await; | 376 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 377 | |||
| 378 | // Fetch raw metrics to debug | ||
| 379 | let syncing_url = harness.syncing_relay_url().expect("Syncing relay should be started"); | ||
| 380 | let raw_1 = fetch_metrics(syncing_url) | ||
| 381 | .await | ||
| 382 | .expect("Failed to fetch metrics"); | ||
| 383 | |||
| 384 | // Print all sync-related metrics | ||
| 385 | println!("\n=== RAW METRICS (t1) ==="); | ||
| 386 | for line in raw_1.lines() { | ||
| 387 | if line.contains("sync") || line.contains("connection") { | ||
| 388 | println!("{}", line); | ||
| 389 | } | ||
| 390 | } | ||
| 391 | println!("========================\n"); | ||
| 392 | |||
| 378 | let metrics_1 = harness.get_metrics().await.unwrap(); | 393 | let metrics_1 = harness.get_metrics().await.unwrap(); |
| 379 | 394 | ||
| 380 | // Wait for more attempts | 395 | // Wait for more attempts |
| 381 | tokio::time::sleep(Duration::from_secs(2)).await; | 396 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 397 | |||
| 398 | // Fetch raw metrics again | ||
| 399 | let syncing_url = harness.syncing_relay_url().expect("Syncing relay should be started"); | ||
| 400 | let raw_2 = fetch_metrics(syncing_url) | ||
| 401 | .await | ||
| 402 | .expect("Failed to fetch metrics"); | ||
| 403 | |||
| 404 | // Print all sync-related metrics | ||
| 405 | println!("\n=== RAW METRICS (t2) ==="); | ||
| 406 | for line in raw_2.lines() { | ||
| 407 | if line.contains("sync") || line.contains("connection") { | ||
| 408 | println!("{}", line); | ||
| 409 | } | ||
| 410 | } | ||
| 411 | println!("========================\n"); | ||
| 412 | |||
| 382 | let metrics_2 = harness.get_metrics().await.unwrap(); | 413 | let metrics_2 = harness.get_metrics().await.unwrap(); |
| 383 | 414 | ||
| 384 | // Failure counter should have increased | 415 | // Failure counter should have increased |
| @@ -496,7 +527,6 @@ async fn test_relay_connected_status() { | |||
| 496 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | 527 | /// NOTE: This test may fail until sync metrics recording is fully wired up. |
| 497 | /// The test documents the expected behavior. | 528 | /// The test documents the expected behavior. |
| 498 | #[tokio::test] | 529 | #[tokio::test] |
| 499 | #[ignore] // Ignored until sync metrics are fully wired up | ||
| 500 | async fn test_health_state_degrades_on_failure() { | 530 | async fn test_health_state_degrades_on_failure() { |
| 501 | use crate::common::sync_helpers::MetricsTestHarness; | 531 | use crate::common::sync_helpers::MetricsTestHarness; |
| 502 | 532 | ||