use super::*; #[tokio::test] async fn async_test_u8_timeout() { let container: Rusturn = Rusturn::new(); let directly: Access<&Rusturn, _> = container.instant_access(); let suspending: Access<&Rusturn, _> = container.suspending_access(); let start: Instant = Instant::now(); let timeout: Duration = Duration::from_millis(400u64); let await_result: TryValueFetchResult<'_, u8, AwaitingAccessError> = suspending.receive_with_timeout(timeout).await; assert!( start.elapsed() >= timeout, "awaiting of specified timeout failed" ); assert!(matches!( await_result.unwrap_err(), TryAccessError::NotAccessible(AwaitingAccessError::TimedOut) )); assert!(directly.try_take().unwrap().is_none()); } #[tokio::test] async fn async_test_u8_do_not_await_timeout() { let container: Rusturn = Rusturn::new(); let directly: Access<&Rusturn, _> = container.instant_access(); let suspending: Access<&Rusturn, _> = container.suspending_access(); let _: () = directly.try_publish(60u8).unwrap(); let start: Instant = Instant::now(); let timeout: Duration = Duration::from_secs(20u64); let await_result: TryValueFetchResult<'_, u8, AwaitingAccessError> = suspending.receive_with_timeout(timeout).await; assert!( start.elapsed() < timeout, "awaited timeout even when result was available" ); assert_eq!(await_result.unwrap(), 60u8); assert!(directly.try_take().unwrap().is_none()); } #[tokio::test] async fn async_test_u8_zero_timeout() { let container: Rusturn = Rusturn::new(); let directly: Access<&Rusturn, _> = container.instant_access(); let suspending: Access<&Rusturn, _> = container.suspending_access(); let await_result: TryValueFetchResult<'_, u8, AwaitingAccessError> = suspending.receive_with_timeout(Duration::ZERO).await; assert!(matches!( await_result.unwrap_err(), TryAccessError::NotAccessible(AwaitingAccessError::TimedOut) )); assert!(directly.try_take().unwrap().is_none()); }