use std::time::{Duration, Instant};
use super::{FLUSH, Fake, Recorded};
use crate::event::Event;
#[tokio::test]
async fn fake_events_with_no_handles_is_empty() {
let fake = Fake::new();
let started = Instant::now();
assert_eq!(fake.events().await, Vec::new());
let recorded = fake.recorded().await;
assert_eq!(recorded.events, Vec::new());
assert!(recorded.settled, "no handle, so no flush timed out");
fake.assert_nothing_tracked().await;
assert!(
started.elapsed() < Duration::from_millis(500),
"{:?}",
started.elapsed()
);
}
#[test]
fn recorded_names_the_flush_timeout_when_a_flush_timed_out() {
let late = Recorded {
events: Vec::new(),
settled: false,
};
let text = late.to_string();
assert!(text.starts_with("recorded: []"), "{text}");
assert!(
text.contains(&format!("within the {} s flush", FLUSH.as_secs())),
"{text}"
);
let settled = Recorded {
events: Vec::new(),
settled: true,
};
assert_eq!(settled.to_string(), "recorded: []");
}
#[test]
fn recorded_lists_each_event() {
let call = Event {
event_type: "mcp:tools/call".to_owned(),
resource_name: Some("echo".to_owned()),
..Event::default()
};
let custom = Event {
event_type: "agentcat:custom".to_owned(),
..Event::default()
};
let recorded = Recorded {
events: vec![call, custom],
settled: true,
};
assert_eq!(
recorded.to_string(),
"recorded: [mcp:tools/call echo, agentcat:custom -]"
);
}