Skip to main content

clankers_testing/
assertions.rs

1use std::time::Duration;
2
3use clankers_core::RobotResult;
4
5use crate::context::ReplayTestResult;
6
7pub fn assert_topic_exists(result: &ReplayTestResult, topic: &str) -> RobotResult<()> {
8    if result.topics_seen.iter().any(|t| t == topic) {
9        Ok(())
10    } else {
11        Err(clankers_core::RobotError::Other(format!(
12            "expected topic '{topic}' not seen during replay; got: {:?}",
13            result.topics_seen
14        )))
15    }
16}
17
18pub fn assert_max_latency(result: &ReplayTestResult, max: Duration) -> RobotResult<()> {
19    if let Some(p99) = result.replay.latency.p99() {
20        if p99 > max {
21            return Err(clankers_core::RobotError::Other(format!(
22                "p99 latency {:?} exceeds max {:?}",
23                p99, max
24            )));
25        }
26    }
27    Ok(())
28}
29
30pub fn assert_no_panics(result: &ReplayTestResult) -> RobotResult<()> {
31    if result.panics > 0 {
32        return Err(clankers_core::RobotError::Other(format!(
33            "expected no panics, got {}",
34            result.panics
35        )));
36    }
37    Ok(())
38}
39
40pub fn assert_dropped_messages(result: &ReplayTestResult, max: u64) -> RobotResult<()> {
41    if result.replay.summary.dropped_messages > max {
42        return Err(clankers_core::RobotError::Other(format!(
43            "dropped {} messages, max allowed {}",
44            result.replay.summary.dropped_messages, max
45        )));
46    }
47    Ok(())
48}