1 use crate::error::Result; 2 3 use super::*; 4 5 use std::net::SocketAddr; 6 use std::str::FromStr; 7 8 const DEMO_IP: &str = "1.2.3.4"; 9 10 #[tokio::test] 11 async fn test_chunk_queue() -> Result<()> { 12 let c: Box<dyn Chunk> = Box::new(ChunkUdp::new( 13 SocketAddr::from_str("192.188.0.2:1234")?, 14 SocketAddr::from_str(&(DEMO_IP.to_owned() + ":5678"))?, 15 )); 16 17 let q = ChunkQueue::new(0); 18 19 let d = q.peek().await; 20 assert!(d.is_none(), "should return none"); 21 22 let ok = q.push(c.clone_to()).await; 23 assert!(ok, "should succeed"); 24 25 let d = q.pop().await; 26 assert!(d.is_some(), "should succeed"); 27 if let Some(d) = d { 28 assert_eq!(c.to_string(), d.to_string(), "should be the same"); 29 } 30 31 let d = q.pop().await; 32 assert!(d.is_none(), "should fail"); 33 34 let q = ChunkQueue::new(1); 35 let ok = q.push(c.clone_to()).await; 36 assert!(ok, "should succeed"); 37 38 let ok = q.push(c.clone_to()).await; 39 assert!(!ok, "should fail"); 40 41 let d = q.peek().await; 42 assert!(d.is_some(), "should succeed"); 43 if let Some(d) = d { 44 assert_eq!(c.to_string(), d.to_string(), "should be the same"); 45 } 46 47 Ok(()) 48 } 49