use std::time::Duration; use tokio::sync::oneshot; use crate::{client::Client, config::ServerConfig, server::Server}; #[tokio::test] async fn expiration() -> Result<(), Box> { let config = ServerConfig::builder().host("127.0.0.1".into()).build(); let mut server = Server::new(&config).await?; let (shutdown_tx, shutdown_rx) = oneshot::channel(); let server_handle = tokio::spawn(async move { server.run(shutdown_rx).await }); let mut client = client("127.0.0.1:6171").await?; client .set("test-key", "test-value".as_bytes(), Some(2)) .await .unwrap(); assert!(client.has("test-key").await.unwrap()); tokio::time::sleep(Duration::from_secs(1)).await; assert!(client.has("test-key").await.unwrap()); tokio::time::sleep(Duration::from_secs(2)).await; assert!(!client.has("test-key").await.unwrap()); shutdown_tx.send(()).unwrap(); server_handle.await??; Ok(()) } async fn client( addr: A, ) -> Result> { Ok(Client::new(addr).await?) }