diff --git a/server/src/db.rs b/server/src/db.rs index de196766e1..8351b9d224 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -328,13 +328,20 @@ impl Db { .fetch_all(&self.0) .await } -} -impl std::ops::Deref for Db { - type Target = sqlx::PgPool; - - fn deref(&self) -> &Self::Target { - &self.0 + #[cfg(test)] + pub async fn close(&self, db_name: &str) { + let query = " + SELECT pg_terminate_backend(pg_stat_activity.pid) + FROM pg_stat_activity + WHERE pg_stat_activity.datname = '{}' AND pid <> pg_backend_pid(); + "; + sqlx::query(query) + .bind(db_name) + .execute(&self.0) + .await + .unwrap(); + self.0.close().await; } } diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 377cf5af4c..91dda0964f 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -920,7 +920,7 @@ mod tests { use crate::{ auth, db::{self, UserId}, - github, rpc, AppState, Config, + github, AppState, Config, }; use async_std::{sync::RwLockReadGuard, task}; use gpui::{ModelHandle, TestAppContext}; @@ -930,7 +930,7 @@ mod tests { use sqlx::{ migrate::{MigrateDatabase, Migrator}, types::time::OffsetDateTime, - Executor as _, Postgres, + Postgres, }; use std::{path::Path, sync::Arc, time::Duration}; use zed::{ @@ -1645,21 +1645,7 @@ mod tests { fn drop(&mut self) { task::block_on(async { self.peer.reset().await; - self.app_state - .db - .execute( - format!( - " - SELECT pg_terminate_backend(pg_stat_activity.pid) - FROM pg_stat_activity - WHERE pg_stat_activity.datname = '{}' AND pid <> pg_backend_pid();", - self.db_name, - ) - .as_str(), - ) - .await - .unwrap(); - self.app_state.db.close().await; + self.app_state.db.close(&self.db_name).await; Postgres::drop_database(&self.app_state.config.database_url) .await .unwrap();