diff options
Diffstat (limited to 'tests/sync/metrics.rs')
| -rw-r--r-- | tests/sync/metrics.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index f1f19d0..e0e9d48 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs | |||
| @@ -412,20 +412,30 @@ async fn test_connection_failure_increments_counter() { | |||
| 412 | async fn test_live_sync_event_count() { | 412 | async fn test_live_sync_event_count() { |
| 413 | let mut harness = MetricsTestHarness::with_sources(1).await; | 413 | let mut harness = MetricsTestHarness::with_sources(1).await; |
| 414 | 414 | ||
| 415 | // Start syncing BEFORE adding events | 415 | // Pre-allocate syncing relay port to include in announcements |
| 416 | harness.start_syncing_relay(0).await; | 416 | let sync_port = TestRelay::find_free_port(); |
| 417 | let sync_domain = format!("127.0.0.1:{}", sync_port); | ||
| 418 | |||
| 419 | // Start syncing relay with pre-allocated port | ||
| 420 | harness.start_syncing_relay_on_port(0, sync_port).await; | ||
| 417 | tokio::time::sleep(Duration::from_secs(2)).await; | 421 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 418 | 422 | ||
| 419 | // Now add events - these should be "live" not "startup" | 423 | // Now add events - these should be "live" not "startup" |
| 424 | // Include BOTH domains so events are accepted by both relays | ||
| 420 | let keys = Keys::generate(); | 425 | let keys = Keys::generate(); |
| 421 | let events: Vec<_> = (0..2) | 426 | let events: Vec<_> = (0..2) |
| 422 | .map(|i| { | 427 | .map(|i| { |
| 423 | create_repo_announcement(&keys, &[&harness.source_domain(0)], &format!("live-{}", i)) | 428 | create_repo_announcement( |
| 429 | &keys, | ||
| 430 | &[&harness.source_domain(0), &sync_domain], | ||
| 431 | &format!("live-{}", i), | ||
| 432 | ) | ||
| 424 | }) | 433 | }) |
| 425 | .collect(); | 434 | .collect(); |
| 426 | harness.submit_events(0, &events).await.unwrap(); | 435 | harness.submit_events(0, &events).await.unwrap(); |
| 427 | 436 | ||
| 428 | tokio::time::sleep(Duration::from_secs(2)).await; | 437 | // Wait longer for live events to be processed and metrics updated |
| 438 | tokio::time::sleep(Duration::from_secs(4)).await; | ||
| 429 | let metrics = harness.get_metrics().await.unwrap(); | 439 | let metrics = harness.get_metrics().await.unwrap(); |
| 430 | 440 | ||
| 431 | let live_count = metrics.events_total("live"); | 441 | let live_count = metrics.events_total("live"); |
| @@ -532,7 +542,25 @@ async fn test_multi_source_aggregate_counts() { | |||
| 532 | // Note: Current impl only supports ONE sync source, so this tests | 542 | // Note: Current impl only supports ONE sync source, so this tests |
| 533 | // that with one source, tracked=1 and connected=1 | 543 | // that with one source, tracked=1 and connected=1 |
| 534 | let mut harness = MetricsTestHarness::with_sources(1).await; | 544 | let mut harness = MetricsTestHarness::with_sources(1).await; |
| 535 | harness.start_syncing_relay(0).await; | 545 | |
| 546 | // Pre-allocate syncing relay port and create an announcement that includes both domains | ||
| 547 | let sync_port = TestRelay::find_free_port(); | ||
| 548 | let sync_domain = format!("127.0.0.1:{}", sync_port); | ||
| 549 | |||
| 550 | // Create announcement on source that references both relays | ||
| 551 | let keys = Keys::generate(); | ||
| 552 | let announcement = create_repo_announcement( | ||
| 553 | &keys, | ||
| 554 | &[&harness.source_domain(0), &sync_domain], | ||
| 555 | "test-repo", | ||
| 556 | ); | ||
| 557 | harness | ||
| 558 | .submit_events(0, &[announcement]) | ||
| 559 | .await | ||
| 560 | .unwrap(); | ||
| 561 | |||
| 562 | // Now start syncing relay - it should sync the existing announcement | ||
| 563 | harness.start_syncing_relay_on_port(0, sync_port).await; | ||
| 536 | tokio::time::sleep(Duration::from_secs(2)).await; | 564 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 537 | 565 | ||
| 538 | let metrics = harness.get_metrics().await.unwrap(); | 566 | let metrics = harness.get_metrics().await.unwrap(); |
| @@ -553,7 +581,8 @@ async fn test_multi_source_aggregate_counts() { | |||
| 553 | 581 | ||
| 554 | // Stop source, verify connected drops to 0 | 582 | // Stop source, verify connected drops to 0 |
| 555 | harness.stop_source(0).await; | 583 | harness.stop_source(0).await; |
| 556 | tokio::time::sleep(Duration::from_secs(2)).await; | 584 | // Wait longer for disconnect to be detected and metrics updated |
| 585 | tokio::time::sleep(Duration::from_secs(4)).await; | ||
| 557 | 586 | ||
| 558 | let metrics = harness.get_metrics().await.unwrap(); | 587 | let metrics = harness.get_metrics().await.unwrap(); |
| 559 | 588 | ||