Skip to content

Commit

Permalink
Add idle test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Jul 5, 2024
1 parent 63fcefa commit f3e62a1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions edb/server/conn_pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ impl<C: Connector> Pool<C> {
self.blocks.summary()
}

pub fn idle(&self) -> bool {
self.blocks.is_empty()
}

pub async fn shutdown(self: Rc<Self>) {
_ = tokio::task::spawn_local(async {
let mut pool = self;
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit f3e62a1

Please sign in to comment.