@@ -141,8 +141,11 @@ pub async fn setup_migrations(environment: &str) {
141
141
#[ cfg( test) ]
142
142
pub mod tests_postgres {
143
143
use std:: {
144
- ops:: { Deref , DerefMut } ,
145
- sync:: atomic:: { AtomicUsize , Ordering } ,
144
+ ops:: Deref ,
145
+ sync:: {
146
+ atomic:: { AtomicUsize , Ordering } ,
147
+ Arc ,
148
+ } ,
146
149
} ;
147
150
148
151
use deadpool:: managed:: { Manager as ManagerTrait , RecycleResult } ;
@@ -173,6 +176,17 @@ pub mod tests_postgres {
173
176
/// we need to know the name of the database we've created.
174
177
/// This will allow us the drop the database when we are recycling the connection
175
178
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 {
176
190
/// The database name that will be created by the pool `CREATE DATABASE`
177
191
/// This database will be set on configuration level of the underlying connection Pool for tests
178
192
pub name : String ,
@@ -182,13 +196,7 @@ pub mod tests_postgres {
182
196
impl Deref for Database {
183
197
type Target = deadpool_postgres:: Pool ;
184
198
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
192
200
}
193
201
}
194
202
@@ -262,14 +270,11 @@ pub mod tests_postgres {
262
270
deadpool_postgres:: Manager :: from_config ( config, NoTls , self . manager_config . clone ( ) ) ;
263
271
let pool = deadpool_postgres:: Pool :: new ( manager, 15 ) ;
264
272
265
- Ok ( Database {
266
- name : db_name,
267
- pool,
268
- } )
273
+ Ok ( Database :: new ( db_name, pool) )
269
274
}
270
275
271
276
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) ;
273
278
let result = self
274
279
. base_pool
275
280
. get ( )
0 commit comments