#![cfg(feature = "stream")]
use std::{iter, net::Ipv4Addr, time::Duration};
use futures_util::StreamExt;
use massping::V4Pinger;
use tokio::time;
#[tokio::test(flavor = "current_thread")]
async fn unsubscribe_after_wraparound_does_not_break_new_round() {
let pinger = V4Pinger::new().unwrap();
let stale = pinger.measure_many(iter::empty::<Ipv4Addr>());
for _ in 0..65535 {
drop(pinger.measure_many(iter::empty::<Ipv4Addr>()));
}
let mut current = pinger.measure_many([Ipv4Addr::LOCALHOST].into_iter());
drop(stale);
let result = time::timeout(Duration::from_secs(5), current.next()).await;
match result {
Ok(Some((addr, _rtt))) => assert_eq!(addr, Ipv4Addr::LOCALHOST),
Ok(None) => panic!("stream ended without a reply"),
Err(_) => panic!("no reply: the stale unsubscribe broke the current round"),
}
}