extern crate memorix_redis; mod example_schema_generated; // use memorix_redis::StreamExt; async fn get_memorix() -> Result> { let redis_url = std::env::var("REDIS_URL").expect("missing environment variable REDIS_URL"); let memorix = example_schema_generated::Memorix::new(&redis_url).await?; Ok(memorix) } // async fn dequeue_and_return( // mut memorix: example_schema_generated::Memorix, // ) -> Result<(), Box> { // let mut stream = memorix.task.runAlgo.dequeue().await.unwrap(); // let res = match stream.next().await { // Some(x) => x.unwrap(), // _ => panic!("Should not happen"), // }; // println!("Res is {}", res); // Ok(()) // } mod tests { #[tokio::test] async fn set_get() -> Result<(), Box> { let mut memorix = crate::get_memorix().await?; memorix .cache .favoriteAnimal .set( &"123".to_string(), &crate::example_schema_generated::Animal::dog, ) .await?; tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; let favorite_animal = memorix.cache.favoriteAnimal.get(&"123".to_string()).await?; assert_eq!( favorite_animal, Some(crate::example_schema_generated::Animal::dog) ); Ok(()) } #[tokio::test] async fn set_get_expire() -> Result<(), Box> { let mut memorix = crate::get_memorix().await?; memorix .cache .favoriteAnimal .set( &"123".to_string(), &crate::example_schema_generated::Animal::dog, ) .await?; tokio::time::sleep(tokio::time::Duration::from_millis(2500)).await; let favorite_animal = memorix.cache.favoriteAnimal.get(&"123".to_string()).await?; assert_eq!(favorite_animal, None); Ok(()) } // #[tokio::test] // #[ntest::timeout(2_000)] // async fn task_returns() -> Result<(), Box> { // let mut memorix = crate::get_memorix().await.unwrap(); // let futures_v: Vec< // std::pin::Pin< // Box>>>, // >, // > = vec![ // Box::pin(crate::dequeue_and_return(memorix.clone())), // Box::pin(async move { // let mut res = memorix.task.runAlgo.queue(&"123".to_string()).await?; // let returns = res.get_returns().await?; // assert_eq!(returns, crate::example_schema_generated::Animal::dog); // Ok(()) // }), // ]; // futures::future::select_all(futures_v).await.0.unwrap(); // Ok(()) // } }