mod common;
use common::MockFrameTransport;
use futures::StreamExt;
use std::sync::Arc;
use std::time::Duration;
use velo::streaming::{AnchorManager, StreamError};
use velo_ext::WorkerId;
#[tokio::test] async fn test_09_inactivity_timeout() {
tokio::time::pause();
let transport = Arc::new(MockFrameTransport::new());
let mgr = Arc::new(AnchorManager::new(WorkerId::from_u64(1), transport));
let mut anchor = mgr.create_anchor::<u32>();
anchor.set_timeout(Some(Duration::from_secs(1)));
tokio::time::advance(Duration::from_millis(1100)).await;
tokio::task::yield_now().await;
let result = anchor.next().await;
assert!(
result.is_none(),
"stream must yield None after inactivity timeout, got {:?}",
result
);
}
#[tokio::test] async fn test_10_heartbeat_timeout() {
tokio::time::pause();
let transport = Arc::new(MockFrameTransport::new());
let mgr = Arc::new(AnchorManager::new(WorkerId::from_u64(1), transport));
let mut anchor = mgr.create_anchor::<u32>();
let handle = anchor.handle();
let sender = mgr
.attach_stream_anchor::<u32>(handle)
.await
.expect("attach must succeed");
tokio::time::advance(Duration::from_secs(16)).await;
tokio::task::yield_now().await;
drop(sender);
let frame = tokio::time::timeout(Duration::from_secs(5), anchor.next())
.await
.expect("stream must resolve within 5s");
assert!(
matches!(frame, Some(Err(StreamError::SenderDropped))),
"stream must yield SenderDropped after sender drop, got {:?}",
frame
);
assert!(
anchor.next().await.is_none(),
"stream exhausted after SenderDropped"
);
}