docs(stats): scope the exact-median contract to the cumulative snapshot

Rolling snapshots are recomputed with `SampleMode::RunningOnly` regardless
of the configured sample mode, so the new `SampleMode::Exact` wording — that
every timing metric a `Snapshot` exposes reports a median — was not true of
`rolling_count()` and `rolling_time()`.

Scope the promise to the cumulative snapshot and say plainly on both rolling
accessors that they use running statistics only and report no median, since
a rolling window is a bounded recent view rather than the run's retained
history. A test pins both halves so the wording cannot quietly go stale.

Rolling retention behavior itself is unchanged.
This commit is contained in:
Nils Andreas Svee committed 2026-08-15 10:48:45 +07:00
1 parent db9bd515bb
commit 71b5819366
2 files changed
+61 -10

No files matched your search

+39
View File
@@ -664,6 +664,45 @@ fn untracked_late_replies_stay_untracked_in_both_policies() {
}
}
#[test]
fn rolling_snapshots_report_no_medians_even_in_exact_mode() {
let mut collector = StatsCollector::new(StatsConfig {
rolling_count: Some(8),
rolling_time: Some(Duration::from_secs(60)),
..StatsConfig::finite()
});
for seq in 0..3 {
collector.process(&sent(seq, ts(u64::from(seq) * 10)));
collector.process(&adjusted_reply(
seq,
10 + u64::from(seq),
9 + i128::from(seq),
));
}
// The cumulative snapshot keeps the exact-mode contract...
let cumulative = collector.snapshot();
assert!(cumulative.rtt.primary.median_ns.is_some());
assert!(cumulative.send_call.median_ns.is_some());
assert!(cumulative.server_processing.processing.median_ns.is_some());
// ...while a rolling window is a bounded recent view recomputed from
// running statistics, so it reports no median whatever the sample mode.
for rolling in [
collector.rolling_count().unwrap(),
collector.rolling_time().unwrap(),
] {
assert!(
rolling.rtt.primary.count > 0,
"the window should have samples"
);
assert_eq!(rolling.rtt.primary.median_ns, None);
assert_eq!(rolling.send_call.median_ns, None);
assert_eq!(rolling.timer_error.median_ns, None);
assert_eq!(rolling.server_processing.processing.median_ns, None);
}
}
#[test]
fn rolling_snapshots_use_the_same_late_reply_policy() {
let mut collector = StatsCollector::new(StatsConfig {