use super::*; #[test] fn test_u8_timeout() { let container: Rusturn = Rusturn::new(); let blocking: Access<&Rusturn, _> = container.blocking_access(); let start: Instant = Instant::now(); let timeout: Duration = Duration::from_millis(400u64); let await_result: TryValueFetchResult<'_, u8, AwaitingAccessError> = blocking.receive_with_timeout(timeout); assert!( start.elapsed() >= timeout, "awaiting of specified timeout failed" ); assert!(matches!( await_result.unwrap_err(), TryAccessError::NotAccessible(AwaitingAccessError::TimedOut) )); assert!(blocking.take().unwrap().is_none()); } #[test] fn test_u8_do_not_await_timeout() { let container: Rusturn = Rusturn::new(); let directly: Access<&Rusturn, _> = container.instant_access(); let blocking: Access<&Rusturn, _> = container.blocking_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> = blocking.receive_with_timeout(timeout); assert!( start.elapsed() < timeout, "awaited timeout even when result was available" ); assert_eq!(await_result.unwrap(), 60u8); assert!(blocking.take().unwrap().is_none()); } #[test] fn test_u8_zero_timeout() { let container: Rusturn = Rusturn::new(); let blocking: Access<&Rusturn, _> = container.blocking_access(); let await_result: TryValueFetchResult<'_, u8, AwaitingAccessError> = blocking.receive_with_timeout(Duration::ZERO); assert!(matches!( await_result.unwrap_err(), TryAccessError::NotAccessible(AwaitingAccessError::TimedOut) )); assert!(blocking.take().unwrap().is_none()); }