11use crate :: dependence_chain:: { LockMngr , LockingReason } ;
22use serial_test:: serial;
33use sqlx:: postgres:: PgPoolOptions ;
4- use test_harness:: instance:: ImportMode ;
4+ use test_harness:: instance:: { DBInstance , 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 . as_str ( ) )
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 . as_str ( ) )
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,7 +212,7 @@ async fn insert_dependence_chains(
199212 Ok ( out)
200213}
201214
202- async fn setup ( ) -> sqlx :: PgPool {
215+ async fn setup ( ) -> DBInstance {
203216 let _ = tracing_subscriber:: fmt ( ) . json ( ) . with_level ( true ) . try_init ( ) ;
204217 let test_instance = test_harness:: instance:: setup_test_db ( ImportMode :: None )
205218 . await
@@ -216,5 +229,5 @@ async fn setup() -> sqlx::PgPool {
216229 . await
217230 . unwrap ( ) ;
218231
219- pool
232+ test_instance
220233}
0 commit comments