pub mod client;
pub mod corpus;
pub mod execute;
pub mod jitter;
pub mod pack;
pub mod resources;
pub mod schedule;
pub mod window;
pub(crate) fn fnv1a(seed: u64, parts: &[u64]) -> u64 {
let mut hash: u64 = 0xcbf2_9ce4_8422_2325 ^ seed;
for part in parts {
for byte in part.to_le_bytes() {
hash ^= u64::from(byte);
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
}
}
hash
}
static RATE_LIMITED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
pub(crate) fn note_rate_limited() {
RATE_LIMITED.store(true, std::sync::atomic::Ordering::Relaxed);
}
#[must_use]
pub fn rate_limited_observed() -> bool {
RATE_LIMITED.load(std::sync::atomic::Ordering::Relaxed)
}
#[must_use]
pub fn rate_limited_refusal(instrument: &str) -> String {
format!(
"{instrument}: the SUT answered 429 — the measurement would record the \
rate limiter's ceiling, not the server's. Measurement requires the \
SUT's rate limiter disabled, or raised above the ladder's peak \
arrival rate, for the duration of the window; the switch that does \
that is the SUT's own, and the party declares it in its IXIT. Run \
again once the window is unlimited."
)
}
pub fn refuse_rate_limited_record(instrument: &str) -> Result<(), String> {
if rate_limited_observed() {
return Err(rate_limited_refusal(instrument));
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::{note_rate_limited, rate_limited_observed, refuse_rate_limited_record};
#[test]
fn a_clean_window_publishes() {
assert!(
!rate_limited_observed(),
"nothing in this process observed a 429"
);
assert_eq!(refuse_rate_limited_record("perf"), Ok(()));
assert_eq!(refuse_rate_limited_record("stress"), Ok(()));
}
#[test]
fn a_rate_limited_window_is_never_published() {
note_rate_limited();
assert!(rate_limited_observed(), "the 429 observation did not latch");
let perf = refuse_rate_limited_record("perf")
.expect_err("a latched 429 withholds the measured record");
assert!(perf.starts_with("perf: "), "{perf}");
assert!(perf.contains("429"), "{perf}");
let stress = refuse_rate_limited_record("stress")
.expect_err("a latched 429 withholds the stress record");
assert!(stress.starts_with("stress: "), "{stress}");
}
}