diff --git a/edb/server/conn_pool/src/pool.rs b/edb/server/conn_pool/src/pool.rs index c85daed5b57b..e52b64281476 100644 --- a/edb/server/conn_pool/src/pool.rs +++ b/edb/server/conn_pool/src/pool.rs @@ -232,6 +232,10 @@ impl Pool { self.blocks.summary() } + pub fn idle(&self) -> bool { + self.blocks.is_empty() + } + pub async fn shutdown(self: Rc) { _ = tokio::task::spawn_local(async { let mut pool = self; @@ -278,6 +282,27 @@ mod tests { .await } + #[test(tokio::test(flavor = "current_thread", start_paused = true))] + async fn test_pool_eventually_idles() -> Result<()> { + let future = async { + let config = PoolConfig::suggested_default_for(10); + + let pool = Pool::new(config, BasicConnector::no_delay()); + let conn = pool.acquire("1").await?; + tokio::time::sleep(Duration::from_millis(10)).await; + drop(conn); + + while !pool.idle() { + tokio::time::sleep(Duration::from_millis(10)).await; + pool.run_once(); + } + + pool.shutdown().await; + Ok(()) + }; + tokio::time::timeout(Duration::from_secs(60), LocalSet::new().run_until(future)).await? + } + #[test(tokio::test(flavor = "current_thread", start_paused = true))] #[rstest] #[case::one(1)]