tests: rework the actually useful tests to live in the integration crate
Rust CI / cargo fmt (push) Successful in 17s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (push) Successful in 34s
Rust CI / cargo clippy (push) Successful in 35s
Rust CI / cargo check (x86_64-unknown-linux-musl) (push) Failing after 8s
Rust CI / cargo test (x86_64-unknown-linux-musl) (push) Failing after 10s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (push) Successful in 1m14s
Rust CI / cargo doc (push) Successful in 23s
Fuzz Smoke / cargo fuzz smoke (push) Failing after 29s
Supply chain / cargo-deny advisories (push) Successful in 9s
Supply chain / cargo-deny bans licenses sources (push) Successful in 5s
Supply chain / actionlint (push) Successful in 3s
Netem Interop / netem interop (push) Successful in 1m11s
Rust CI / cargo fmt (push) Successful in 17s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (push) Successful in 34s
Rust CI / cargo clippy (push) Successful in 35s
Rust CI / cargo check (x86_64-unknown-linux-musl) (push) Failing after 8s
Rust CI / cargo test (x86_64-unknown-linux-musl) (push) Failing after 10s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (push) Successful in 1m14s
Rust CI / cargo doc (push) Successful in 23s
Fuzz Smoke / cargo fuzz smoke (push) Failing after 29s
Supply chain / cargo-deny advisories (push) Successful in 9s
Supply chain / cargo-deny bans licenses sources (push) Successful in 5s
Supply chain / actionlint (push) Successful in 3s
Netem Interop / netem interop (push) Successful in 1m11s
This commit is contained in:
101 files changed
+3636
-15159
No files matched your search
@@ -0,0 +1,112 @@
|
||||
use std::time::{Duration, Instant, UNIX_EPOCH};
|
||||
|
||||
use irtt_client::{
|
||||
ClientEvent, ClientTimestamp, PacketMeta, RttSample, ServerTiming, SignedDuration,
|
||||
};
|
||||
use irtt_stats::{StatsCollector, StatsConfig};
|
||||
|
||||
fn reply(
|
||||
base: Instant,
|
||||
seq: u32,
|
||||
send_ms: u64,
|
||||
receive_ms: u64,
|
||||
timing: ServerTiming,
|
||||
) -> ClientEvent {
|
||||
let raw = Duration::from_millis(receive_ms - send_ms);
|
||||
ClientEvent::EchoReply {
|
||||
seq,
|
||||
remote: "127.0.0.1:2112".parse().unwrap(),
|
||||
sent_at: ClientTimestamp {
|
||||
mono: base + Duration::from_millis(send_ms),
|
||||
wall: UNIX_EPOCH + Duration::from_millis(200 + u64::from(seq) * 10),
|
||||
},
|
||||
received_at: ClientTimestamp {
|
||||
mono: base + Duration::from_millis(receive_ms),
|
||||
wall: UNIX_EPOCH + Duration::from_millis(240 + u64::from(seq) * 20),
|
||||
},
|
||||
rtt: RttSample {
|
||||
raw,
|
||||
adjusted: None,
|
||||
effective: SignedDuration::from_duration(raw),
|
||||
},
|
||||
server_timing: Some(timing),
|
||||
one_way: None,
|
||||
received_stats: None,
|
||||
bytes: 64,
|
||||
packet_meta: PacketMeta::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn directional_ipdv_uses_matching_clock_domains_and_preserves_zero_and_absence() {
|
||||
let first = ServerTiming {
|
||||
receive_mono_ns: Some(100_000_000),
|
||||
send_mono_ns: Some(101_000_000),
|
||||
receive_wall_ns: Some(1_000_000_000),
|
||||
send_wall_ns: Some(1_001_000_000),
|
||||
midpoint_mono_ns: None,
|
||||
midpoint_wall_ns: None,
|
||||
processing: None,
|
||||
};
|
||||
let second = ServerTiming {
|
||||
receive_mono_ns: Some(105_000_000),
|
||||
send_mono_ns: Some(108_000_000),
|
||||
receive_wall_ns: Some(1_020_000_000),
|
||||
send_wall_ns: Some(1_026_000_000),
|
||||
..first
|
||||
};
|
||||
// Wall and monotonic deltas deliberately disagree: availability alone
|
||||
// cannot prove the formulas or which clock domain wins.
|
||||
let mut wall_only = second;
|
||||
wall_only.receive_mono_ns = None;
|
||||
wall_only.send_mono_ns = None;
|
||||
let mut no_send = wall_only;
|
||||
no_send.receive_wall_ns = None;
|
||||
let mut no_receive = wall_only;
|
||||
no_receive.send_wall_ns = None;
|
||||
let zero = ServerTiming {
|
||||
receive_mono_ns: Some(110_000_000),
|
||||
send_mono_ns: Some(111_000_000),
|
||||
..second
|
||||
};
|
||||
for (label, current, send_ms, expected_send_ms, expected_receive_ms) in [
|
||||
("monotonic preferred", second, 30, Some(5), Some(3)),
|
||||
("wall fallback", wall_only, 30, Some(10), Some(5)),
|
||||
("missing send endpoint", no_send, 30, None, Some(5)),
|
||||
("missing receive endpoint", no_receive, 30, Some(10), None),
|
||||
("reordered client send times", second, 10, Some(15), Some(3)),
|
||||
("zero variation", zero, 30, Some(0), Some(0)),
|
||||
] {
|
||||
let base = Instant::now();
|
||||
let mut collector = StatsCollector::new(StatsConfig::finite());
|
||||
assert!(collector
|
||||
.process(&reply(base, 0, 20, 40, first))
|
||||
.ipdv_pairs
|
||||
.is_empty());
|
||||
let update = collector.process(&reply(base, 1, send_ms, 50, current));
|
||||
assert_eq!(update.ipdv_pairs.len(), 1, "{label}");
|
||||
let pair = &update.ipdv_pairs[0];
|
||||
assert_eq!(
|
||||
pair.send_ipdv,
|
||||
expected_send_ms.map(Duration::from_millis),
|
||||
"{label}"
|
||||
);
|
||||
assert_eq!(
|
||||
pair.receive_ipdv,
|
||||
expected_receive_ms.map(Duration::from_millis),
|
||||
"{label}"
|
||||
);
|
||||
let snapshot = collector.snapshot();
|
||||
for (expected, actual) in [
|
||||
(expected_send_ms, snapshot.ipdv.send),
|
||||
(expected_receive_ms, snapshot.ipdv.receive),
|
||||
] {
|
||||
assert_eq!(actual.count, u64::from(expected.is_some()), "{label}");
|
||||
assert_eq!(
|
||||
actual.total_ns,
|
||||
i128::from(expected.unwrap_or(0)) * 1_000_000,
|
||||
"{label}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,6 @@
|
||||
//! Property tests for the count-based and time-based rolling windows.
|
||||
//!
|
||||
//! [`RollingEvents`] (in `src/rolling.rs`) keeps two independent `VecDeque`s:
|
||||
//! one bounded by [`StatsConfig::rolling_count`] and one bounded by
|
||||
//! [`StatsConfig::rolling_time`]. They are pushed to together but evicted
|
||||
//! independently, and each exposes its own snapshot
|
||||
//! ([`StatsCollector::rolling_count`] / [`StatsCollector::rolling_time`]).
|
||||
//! Reading `rolling.rs` and the existing `rolling_count_eviction_recomputes_*`
|
||||
//! / `rolling_time_eviction_uses_event_timestamps` tests in `tests/stats.rs`
|
||||
//! confirms there is no single window bounded by *both* limits at once: the
|
||||
//! two bounds do not compose as AND or OR on shared storage, they are simply
|
||||
//! two separate parallel windows over the same input stream. This file proves
|
||||
//! that independence generatively: with both bounds configured
|
||||
//! simultaneously, each window must behave exactly as if the *other* bound
|
||||
//! did not exist.
|
||||
//!
|
||||
//! The reference model is a plain `Vec<(ClientEvent, at_ms)>` history that is
|
||||
//! re-filtered from scratch after every operation (once by count, once by
|
||||
//! time), then replayed through a fresh [`StatsCollector`] to obtain a
|
||||
//! [`Snapshot`]. Because [`StatsCollector::rolling_count`] /
|
||||
//! [`StatsCollector::rolling_time`] are themselves computed by replaying the
|
||||
//! retained events through a fresh `CoreStats` on every call (see
|
||||
//! `rolling.rs`'s `snapshot_window`), and because both the production window
|
||||
//! and this reference model process the *same* `ClientEvent` values in the
|
||||
//! *same* order through the *same* pure, deterministic normalization and
|
||||
//! aggregation code, the two snapshots are expected to be bit-for-bit equal,
|
||||
//! not merely close. `Snapshot` derives `PartialEq`, so the comparison below
|
||||
//! is exact `assert_eq!` with no floating-point tolerance: there is no
|
||||
//! independent numerical computation on the reference side to accumulate
|
||||
//! error against, both sides run the identical arithmetic in the identical
|
||||
//! order.
|
||||
//!
|
||||
//! The reference model's time-window recomputation (filter the whole history
|
||||
//! by `at_ms >= latest_at_ms - window_ms`) is only equivalent to the
|
||||
//! production incremental sliding-eviction (which pops from the front using
|
||||
//! the cutoff computed at each push) when event timestamps are pushed in
|
||||
//! non-decreasing order, exactly as `normalization.rs` documents ("Rolling-
|
||||
//! window eviction assumes events are pushed in non-decreasing `at()`
|
||||
//! order"). The operation generator below enforces that by construction: a
|
||||
//! shared clock only ever moves forward, and every generated event borrows
|
||||
//! its `at()` timestamp from the clock's current value.
|
||||
//! Independent count and time windows must match a filtered replay through
|
||||
//! StatsCollector, while cumulative accounting retains the complete history.
|
||||
//! Generated events have non-decreasing normalized window timestamps.
|
||||
|
||||
use std::time::{Duration, Instant, UNIX_EPOCH};
|
||||
|
||||
@@ -208,7 +170,7 @@ fn build_event(op: &Op, seq: u32, clock_ms: u64, base: Instant) -> ClientEvent {
|
||||
Op::Loss => ClientEvent::EchoLoss {
|
||||
seq,
|
||||
sent_at: ts_at(base, clock_ms),
|
||||
timeout_at: ts_at(base, clock_ms).mono,
|
||||
timeout_at: ts_at(base, clock_ms).mono - Duration::from_millis(10),
|
||||
},
|
||||
Op::Warning => ClientEvent::Warning {
|
||||
kind: irtt_client::WarningKind::UntrackedReply,
|
||||
@@ -218,11 +180,7 @@ fn build_event(op: &Op, seq: u32, clock_ms: u64, base: Instant) -> ClientEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/// Replays `events` in order through a fresh collector using the rolling
|
||||
/// windows' own semantics (running statistics only, same late-reply policy),
|
||||
/// mirroring exactly what `rolling.rs`'s private `snapshot_window` does for
|
||||
/// the production windows. This is the "recompute from scratch" reference
|
||||
/// primitive both the count and time reference windows below are built on.
|
||||
/// Public reference: collect exactly the events retained by one window.
|
||||
fn replay(events: &[ClientEvent], late_replies: LateReplyMode) -> Snapshot {
|
||||
let mut collector = StatsCollector::new(StatsConfig {
|
||||
samples: SampleMode::RunningOnly,
|
||||
@@ -275,6 +233,11 @@ proptest! {
|
||||
// scratch after every step.
|
||||
let mut history: Vec<(ClientEvent, u64)> = Vec::new();
|
||||
|
||||
// Force a loss whose clamped time evicts the initial send, while its
|
||||
// raw pre-send deadline would retain it. Every generated case must
|
||||
// therefore distinguish the two normalization choices.
|
||||
let ops = [Op::Send, Op::Advance(u16::try_from(time_limit_ms + 5).unwrap()), Op::Loss, Op::Advance(10), Op::Warning]
|
||||
.into_iter().chain(ops).collect::<Vec<_>>();
|
||||
for (idx, op) in ops.iter().enumerate() {
|
||||
if let Op::Advance(delta) = op {
|
||||
clock_ms += u64::from(*delta);
|
||||
|
||||
@@ -319,6 +319,19 @@ fn ipdv_wraparound_sequence_is_adjacent() {
|
||||
assert!(wrapped.contributed_sample);
|
||||
assert_one_ipdv_pair(&wrapped, u32::MAX, 0, Duration::from_millis(4));
|
||||
|
||||
// The client classifies duplicate datagrams before publishing events;
|
||||
// their accounting must not emit an adjacent pair a second time.
|
||||
for seq in [u32::MAX, 0] {
|
||||
let duplicate = collector.process(&ClientEvent::DuplicateReply {
|
||||
seq,
|
||||
remote: "127.0.0.1:2112".parse().unwrap(),
|
||||
received_at: ts(30),
|
||||
bytes: 64,
|
||||
});
|
||||
assert!(!duplicate.contributed_sample);
|
||||
assert_no_ipdv_pairs(&duplicate);
|
||||
}
|
||||
|
||||
let snapshot = collector.snapshot();
|
||||
assert_eq!(snapshot.ipdv.round_trip.count, 1);
|
||||
assert_eq!(snapshot.ipdv.round_trip.total_ns, 4_000_000);
|
||||
@@ -355,19 +368,6 @@ fn late_reply_can_complete_ipdv_pair() {
|
||||
assert_eq!(snapshot.ipdv.round_trip.total_ns, 10_000_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_exposes_directional_ipdv_when_available() {
|
||||
let mut collector = StatsCollector::new(StatsConfig::finite());
|
||||
collector.process(&unadjusted_reply(0, 10));
|
||||
let update = collector.process(&unadjusted_reply(1, 13));
|
||||
|
||||
assert!(update.contributed_sample);
|
||||
|
||||
let pair = assert_one_ipdv_pair(&update, 0, 1, Duration::from_millis(3));
|
||||
assert!(pair.send_ipdv.is_some());
|
||||
assert!(pair.receive_ipdv.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gap_fill_update_exposes_both_completed_ipdv_pairs() {
|
||||
let mut collector = StatsCollector::new(StatsConfig::finite());
|
||||
|
||||
Reference in new issue
Block a user