Skip to content

Commit 3a859d7

Browse files
authored
Merge pull request #406 from AdExNetwork/fix-ci-postgres-tests-failing
Fix CI postgres tests failing
2 parents 19b83f3 + 412a0ce commit 3a859d7

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

sentry/src/db.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ pub async fn setup_migrations(environment: &str) {
141141
#[cfg(test)]
142142
pub mod tests_postgres {
143143
use std::{
144-
ops::{Deref, DerefMut},
145-
sync::atomic::{AtomicUsize, Ordering},
144+
ops::Deref,
145+
sync::{
146+
atomic::{AtomicUsize, Ordering},
147+
Arc,
148+
},
146149
};
147150

148151
use deadpool::managed::{Manager as ManagerTrait, RecycleResult};
@@ -173,6 +176,17 @@ pub mod tests_postgres {
173176
/// we need to know the name of the database we've created.
174177
/// This will allow us the drop the database when we are recycling the connection
175178
pub struct Database {
179+
inner: Arc<DatabaseInner>,
180+
}
181+
impl Database {
182+
pub fn new(name: String, pool: DbPool) -> Self {
183+
Self {
184+
inner: Arc::new(DatabaseInner { name, pool }),
185+
}
186+
}
187+
}
188+
189+
struct DatabaseInner {
176190
/// The database name that will be created by the pool `CREATE DATABASE`
177191
/// This database will be set on configuration level of the underlying connection Pool for tests
178192
pub name: String,
@@ -182,13 +196,7 @@ pub mod tests_postgres {
182196
impl Deref for Database {
183197
type Target = deadpool_postgres::Pool;
184198
fn deref(&self) -> &deadpool_postgres::Pool {
185-
&self.pool
186-
}
187-
}
188-
189-
impl DerefMut for Database {
190-
fn deref_mut(&mut self) -> &mut deadpool_postgres::Pool {
191-
&mut self.pool
199+
&self.inner.pool
192200
}
193201
}
194202

@@ -262,14 +270,11 @@ pub mod tests_postgres {
262270
deadpool_postgres::Manager::from_config(config, NoTls, self.manager_config.clone());
263271
let pool = deadpool_postgres::Pool::new(manager, 15);
264272

265-
Ok(Database {
266-
name: db_name,
267-
pool,
268-
})
273+
Ok(Database::new(db_name, pool))
269274
}
270275

271276
async fn recycle(&self, database: &mut Database) -> RecycleResult<PoolError> {
272-
let queries = format!("DROP DATABASE {0} WITH (FORCE);", database.name);
277+
let queries = format!("DROP DATABASE {0} WITH (FORCE);", database.inner.name);
273278
let result = self
274279
.base_pool
275280
.get()

0 commit comments

Comments
 (0)