- All remaining #[cfg(test)] modules left src/ (manager auth/heartbeat, protocol registry and HTTP parser, traffic hook/prefix/profile, TUI Prometheus); 41 tests moved into 10 integration suites with the same names and assertions, so `grep -rn '#[cfg(test)]' src/` is now empty. - runbook.md: degradation signals (overloaded connections, ClickHouse drops, XDP drops, generic mode, EMFILE backoff) and how to verify XDP was detached. - troubleshooting.md: accept backoff, orphaned XDP, password/JWT startup requirements, ClickHouse event loss. - TODO: review round recorded as fixed/deferred.
38 lines
815 B
Rust
38 lines
815 B
Rust
//! Hourly EWMA traffic profiler: baseline warming and the capped anomaly score.
|
|
|
|
use rampart::traffic::profiler::TrafficProfiler;
|
|
|
|
#[test]
|
|
fn test_profiler_record_and_baseline() {
|
|
let mut p = TrafficProfiler::new();
|
|
p.record(1000.0);
|
|
p.record(1100.0);
|
|
let base = p.baseline();
|
|
assert!(base > 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_anomaly_score_normal() {
|
|
let mut p = TrafficProfiler::new();
|
|
for _ in 0..10 {
|
|
p.record(100.0);
|
|
}
|
|
let score = p.anomaly_score(100.0);
|
|
assert!(score < 2.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_anomaly_score_capped() {
|
|
let mut p = TrafficProfiler::new();
|
|
for _ in 0..10 {
|
|
p.record(1.0);
|
|
}
|
|
let score = p.anomaly_score(1_000_000.0);
|
|
assert!((score - 10.0).abs() < 0.001);
|
|
}
|
|
|
|
#[test]
|
|
fn test_anomaly_score_zero_baseline() {
|
|
let p = TrafficProfiler::new();
|
|
assert_eq!(p.anomaly_score(100.0), 0.0);
|
|
}
|