use assert_matches::assert_matches;
use pyroscope::timer::{Timer, TimerSignal};
use std::time::Duration;
#[test]
fn test_timer() {
let mut timer = Timer::initialize(Duration::from_secs(10)).unwrap();
let (tx, rx) = std::sync::mpsc::channel();
timer.attach_listener(tx).unwrap();
let planned = rx.recv().unwrap();
assert_matches!(planned, TimerSignal::NextSnapshot(planned) => {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
assert!(planned - now < 10);
assert!(planned % 10 == 0);
})
}