test(metrics): bracket sync activity with observable scrapes

The availability test scraped the metrics endpoint three times with a
200 ms timer between requests to sample "during sync". The timer did not
relate the samples to any sync state, so under load all three could
land before the sync connection existed.

Scrape once while the connection to the source is still being
established, wait for the connection gauge to report it through the
existing `wait_for_sync_connection` helper, and scrape again. The two
samples now bracket the connection instead of being spaced by a timer.
The remaining sleeps in this file are the intervals of bounded polls.

Validation: measured against master with the same binaries, 20 unloaded
runs and 30 samples as three concurrent instances under CPU spinners;
see the pull request description.

Assisted-by: Claude Fable 5.1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
DanConwayDev
2026-09-18 14:33:10 +00:00
co-authored by Claude Fable 5.1
parent db451c306d
commit e3afc28fc3
+14 -11
View File
@@ -83,17 +83,20 @@ async fn test_metrics_availability_during_sync() {
wait_for_metrics_ready(sync_relay.url(), Duration::from_secs(30)).await;
// Make multiple metrics requests while sync is active. The 200ms gap is
// deliberate scrape spacing, not a wait for a condition.
for i in 0..3 {
let metrics = fetch_metrics(sync_relay.url()).await;
assert!(
metrics.is_ok(),
"Metrics request {} should succeed during sync",
i + 1
);
tokio::time::sleep(Duration::from_millis(200)).await;
}
// Scrape while the sync connection to the source is still being
// established, then again once the connection gauge reports it, so the
// samples bracket sync activity instead of being spaced by a timer.
assert!(
fetch_metrics(sync_relay.url()).await.is_ok(),
"metrics request should succeed while sync is connecting"
);
wait_for_sync_connection(sync_relay.url(), 1, Duration::from_secs(30))
.await
.expect("sync connection to the source relay should be reported");
assert!(
fetch_metrics(sync_relay.url()).await.is_ok(),
"metrics request should succeed while sync is connected"
);
sync_relay.stop().await;
source_relay.stop().await;