11use crate :: dependence_chain:: { LockMngr , LockingReason } ;
2+ use crate :: tests:: utils:: { setup_test_app, TestInstance } ;
23use serial_test:: serial;
34use sqlx:: postgres:: PgPoolOptions ;
4- use test_harness:: instance:: ImportMode ;
55use tokio:: time:: { sleep, Duration } ;
66use tracing:: info;
77use uuid:: Uuid ;
@@ -11,7 +11,13 @@ const NUM_SAMPLE_CHAINS: usize = 10;
1111#[ tokio:: test]
1212#[ serial( db) ]
1313async fn test_acquire_next_lock ( ) {
14- let pool = setup ( ) . await ;
14+ let instance = setup ( ) . await ;
15+ let pool = sqlx:: postgres:: PgPoolOptions :: new ( )
16+ . max_connections ( 2 )
17+ . connect ( instance. db_url ( ) )
18+ . await
19+ . expect ( "Failed to connect to the database" ) ;
20+
1521 let dependence_chain_ids = insert_dependence_chains ( & pool, NUM_SAMPLE_CHAINS )
1622 . await
1723 . expect ( "inserted chains" ) ;
@@ -52,7 +58,12 @@ async fn test_acquire_next_lock() {
5258#[ tokio:: test]
5359#[ serial( db) ]
5460async fn test_work_stealing ( ) {
55- let pool = setup ( ) . await ;
61+ let instance = setup ( ) . await ;
62+ let pool = sqlx:: postgres:: PgPoolOptions :: new ( )
63+ . max_connections ( 2 )
64+ . connect ( instance. db_url ( ) )
65+ . await
66+ . expect ( "Failed to connect to the database" ) ;
5667
5768 let dependence_chain_ids = insert_dependence_chains ( & pool, NUM_SAMPLE_CHAINS )
5869 . await
@@ -178,7 +189,9 @@ async fn insert_dependence_chains(
178189 let mut out = Vec :: with_capacity ( num_chains) ;
179190
180191 for i in 0 ..num_chains {
192+ info ! ( "Inserting dependence chain {}" , i) ;
181193 let dependence_chain_id = i. to_le_bytes ( ) . to_vec ( ) ;
194+
182195 sqlx:: query!(
183196 r#"
184197 INSERT INTO dependence_chain (dependence_chain_id, status, last_updated_at)
@@ -199,14 +212,12 @@ async fn insert_dependence_chains(
199212 Ok ( out)
200213}
201214
202- async fn setup ( ) -> sqlx :: PgPool {
215+ async fn setup ( ) -> TestInstance {
203216 let _ = tracing_subscriber:: fmt ( ) . json ( ) . with_level ( true ) . try_init ( ) ;
204- let test_instance = test_harness:: instance:: setup_test_db ( ImportMode :: None )
205- . await
206- . expect ( "valid db instance" ) ;
217+ let test_instance = setup_test_app ( ) . await . expect ( "valid db instance" ) ;
207218 let pool = PgPoolOptions :: new ( )
208219 . max_connections ( 2 )
209- . connect ( test_instance. db_url . as_str ( ) )
220+ . connect ( test_instance. db_url ( ) )
210221 . await
211222 . unwrap ( ) ;
212223
@@ -216,5 +227,5 @@ async fn setup() -> sqlx::PgPool {
216227 . await
217228 . unwrap ( ) ;
218229
219- pool
230+ test_instance
220231}
0 commit comments