diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/sync/metrics.rs | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 775159b..3accd0f 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs | |||
| @@ -247,7 +247,12 @@ async fn test_startup_sync_event_count() { | |||
| 247 | // 6. Create 3 patch events (Layer 2) that reference the announcement | 247 | // 6. Create 3 patch events (Layer 2) that reference the announcement |
| 248 | let patches: Vec<_> = (0..3) | 248 | let patches: Vec<_> = (0..3) |
| 249 | .map(|i| { | 249 | .map(|i| { |
| 250 | create_event_referencing_repo(&keys, &repo_coord, KIND_PATCH, &format!("Test patch {}", i)) | 250 | create_event_referencing_repo( |
| 251 | &keys, | ||
| 252 | &repo_coord, | ||
| 253 | KIND_PATCH, | ||
| 254 | &format!("Test patch {}", i), | ||
| 255 | ) | ||
| 251 | }) | 256 | }) |
| 252 | .collect(); | 257 | .collect(); |
| 253 | println!("Created {} patches", patches.len()); | 258 | println!("Created {} patches", patches.len()); |
| @@ -320,8 +325,12 @@ async fn test_startup_sync_event_count() { | |||
| 320 | .kind(Kind::Custom(KIND_PATCH)) | 325 | .kind(Kind::Custom(KIND_PATCH)) |
| 321 | .author(keys.public_key()); | 326 | .author(keys.public_key()); |
| 322 | 327 | ||
| 323 | let patches_synced = | 328 | let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( |
| 324 | crate::common::sync_helpers::wait_for_event_on_relay(syncing_relay.url(), filter, Duration::from_secs(2)).await; | 329 | syncing_relay.url(), |
| 330 | filter, | ||
| 331 | Duration::from_secs(2), | ||
| 332 | ) | ||
| 333 | .await; | ||
| 325 | println!("Patches synced to syncing relay: {}", patches_synced); | 334 | println!("Patches synced to syncing relay: {}", patches_synced); |
| 326 | 335 | ||
| 327 | // Cleanup | 336 | // Cleanup |
| @@ -374,12 +383,15 @@ async fn test_connection_failure_increments_counter() { | |||
| 374 | 383 | ||
| 375 | // Wait for initial connection attempt to the unreachable bootstrap relay | 384 | // Wait for initial connection attempt to the unreachable bootstrap relay |
| 376 | tokio::time::sleep(Duration::from_secs(2)).await; | 385 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 377 | 386 | ||
| 378 | let metrics = harness.get_metrics().await.unwrap(); | 387 | let metrics = harness.get_metrics().await.unwrap(); |
| 379 | 388 | ||
| 380 | // Failure counter should be recorded when connecting to unreachable relay | 389 | // Failure counter should be recorded when connecting to unreachable relay |
| 381 | let failures = metrics | 390 | let failures = metrics |
| 382 | .counter("ngit_sync_connection_attempts_total", &[("result", "failure")]) | 391 | .counter( |
| 392 | "ngit_sync_connection_attempts_total", | ||
| 393 | &[("result", "failure")], | ||
| 394 | ) | ||
| 383 | .unwrap_or(0); | 395 | .unwrap_or(0); |
| 384 | 396 | ||
| 385 | println!("Connection failures recorded: {}", failures); | 397 | println!("Connection failures recorded: {}", failures); |
| @@ -413,7 +425,9 @@ async fn test_live_sync_event_count() { | |||
| 413 | // Now add events - these should be "live" not "startup" | 425 | // Now add events - these should be "live" not "startup" |
| 414 | let keys = Keys::generate(); | 426 | let keys = Keys::generate(); |
| 415 | let events: Vec<_> = (0..2) | 427 | let events: Vec<_> = (0..2) |
| 416 | .map(|i| create_repo_announcement(&keys, &[&harness.source_domain(0)], &format!("live-{}", i))) | 428 | .map(|i| { |
| 429 | create_repo_announcement(&keys, &[&harness.source_domain(0)], &format!("live-{}", i)) | ||
| 430 | }) | ||
| 417 | .collect(); | 431 | .collect(); |
| 418 | harness.submit_events(0, &events).await.unwrap(); | 432 | harness.submit_events(0, &events).await.unwrap(); |
| 419 | 433 | ||
| @@ -434,11 +448,7 @@ async fn test_live_sync_event_count() { | |||
| 434 | /// | 448 | /// |
| 435 | /// This test validates that the ngit_sync_relay_connected gauge | 449 | /// This test validates that the ngit_sync_relay_connected gauge |
| 436 | /// correctly reflects the connection state of source relays. | 450 | /// correctly reflects the connection state of source relays. |
| 437 | /// | ||
| 438 | /// NOTE: This test may fail until sync metrics recording is fully wired up. | ||
| 439 | /// The test documents the expected behavior. | ||
| 440 | #[tokio::test] | 451 | #[tokio::test] |
| 441 | #[ignore] // Enable when relay connected status metrics are wired up | ||
| 442 | async fn test_relay_connected_status() { | 452 | async fn test_relay_connected_status() { |
| 443 | let mut harness = MetricsTestHarness::with_sources(1).await; | 453 | let mut harness = MetricsTestHarness::with_sources(1).await; |
| 444 | harness.start_syncing_relay(0).await; | 454 | harness.start_syncing_relay(0).await; |
| @@ -505,7 +515,10 @@ async fn test_health_state_degrades_on_failure() { | |||
| 505 | // Get the relay status (1=healthy, 2=degraded, 3=dead) | 515 | // Get the relay status (1=healthy, 2=degraded, 3=dead) |
| 506 | let status = later.gauge("ngit_sync_relay_status", &[]).unwrap_or(0); | 516 | let status = later.gauge("ngit_sync_relay_status", &[]).unwrap_or(0); |
| 507 | 517 | ||
| 508 | println!("Initial metrics: {:?}", initial.gauge("ngit_sync_relay_status", &[])); | 518 | println!( |
| 519 | "Initial metrics: {:?}", | ||
| 520 | initial.gauge("ngit_sync_relay_status", &[]) | ||
| 521 | ); | ||
| 509 | println!("Later status: {}", status); | 522 | println!("Later status: {}", status); |
| 510 | 523 | ||
| 511 | assert!( | 524 | assert!( |
| @@ -561,8 +574,14 @@ async fn test_multi_source_aggregate_counts() { | |||
| 561 | 574 | ||
| 562 | let metrics = harness.get_metrics().await.unwrap(); | 575 | let metrics = harness.get_metrics().await.unwrap(); |
| 563 | 576 | ||
| 564 | println!("After stop - Tracked total: {:?}", metrics.relays_tracked_total()); | 577 | println!( |
| 565 | println!("After stop - Connected total: {:?}", metrics.relays_connected_total()); | 578 | "After stop - Tracked total: {:?}", |
| 579 | metrics.relays_tracked_total() | ||
| 580 | ); | ||
| 581 | println!( | ||
| 582 | "After stop - Connected total: {:?}", | ||
| 583 | metrics.relays_connected_total() | ||
| 584 | ); | ||
| 566 | 585 | ||
| 567 | assert_eq!( | 586 | assert_eq!( |
| 568 | metrics.relays_tracked_total(), | 587 | metrics.relays_tracked_total(), |
| @@ -576,4 +595,4 @@ async fn test_multi_source_aggregate_counts() { | |||
| 576 | ); | 595 | ); |
| 577 | 596 | ||
| 578 | harness.stop_all().await; | 597 | harness.stop_all().await; |
| 579 | } \ No newline at end of file | 598 | } |