test: protect durable behavior identified in review

This commit is contained in:
Nils Andreas Svee committed 2026-10-02 16:12:52 +07:00
1 parent e115b96f21
commit 83b3607228
7 files changed
+528 -6

No files matched your search

@@ -16,8 +16,8 @@ async fn both_pacing_modes_serve_every_target_on_its_negotiated_grid() {
for pacing in [ManagedPacing::Burst, ManagedPacing::Staggered] {
let config = ManagedClientConfig {
client: ClientConfig {
duration: Some(Duration::from_millis(200)),
interval: Duration::from_millis(20),
duration: Some(Duration::from_millis(600)),
interval: Duration::from_millis(100),
probe_timeout: Duration::from_millis(100),
open_timeouts: vec![Duration::from_millis(200)],
..ClientConfig::default()
@@ -31,6 +31,7 @@ async fn both_pacing_modes_serve_every_target_on_its_negotiated_grid() {
let mut events = handle.subscribe().unwrap();
let run = tokio::spawn(task);
let mut sends: HashMap<TargetInstance, Vec<_>> = HashMap::new();
let mut actual_sends = Vec::new();
while let Ok(event) = events.recv().await {
if let ManagedEvent::Client {
target,
@@ -44,11 +45,12 @@ async fn both_pacing_modes_serve_every_target_on_its_negotiated_grid() {
{
let scheduled = scheduled_at.expect("managed probes expose their cadence");
assert!(sent_at.mono >= scheduled);
actual_sends.push((target.clone(), sent_at.mono));
let previous = sends.entry(target).or_default();
if let Some(last) = previous.last() {
let elapsed: Duration = scheduled.duration_since(*last);
assert!(!elapsed.is_zero());
assert_eq!(elapsed.as_nanos() % Duration::from_millis(20).as_nanos(), 0);
assert_eq!(elapsed.as_nanos() % Duration::from_millis(100).as_nanos(), 0);
}
previous.push(scheduled);
}
@@ -57,6 +59,19 @@ async fn both_pacing_modes_serve_every_target_on_its_negotiated_grid() {
assert_eq!(outcome.end_reason, ManagedEndReason::TargetsComplete);
assert_eq!(outcome.successful_target_outcomes, 2);
assert_eq!(sends.len(), 2);
actual_sends.sort_by_key(|(_, at)| *at);
let cross_target_gaps = actual_sends.windows(2)
.filter(|pair| pair[0].0 != pair[1].0)
.map(|pair| pair[1].1.duration_since(pair[0].1)).collect::<Vec<_>>();
assert!(cross_target_gaps.len() >= 2);
// Allow timer wake jitter while separating the nominal 50 ms
// stagger spacing from back-to-back burst sends.
match pacing {
ManagedPacing::Burst => assert!(cross_target_gaps.iter().filter(|gap| **gap < Duration::from_millis(25)).count() >= 2,
"burst must repeatedly send different targets back-to-back: {cross_target_gaps:?}"),
ManagedPacing::Staggered => assert!(cross_target_gaps.iter().all(|gap| *gap >= Duration::from_millis(35)),
"staggered must space different targets across the interval: {cross_target_gaps:?}"),
}
for target in outcome.recent_target_outcomes.iter() {
assert!(sends[&target.target].len() >= 2);
assert!(target.replies_received >= 2);