@@ -94,11 +94,7 @@ actor DatabasePool {
9494 }
9595
9696 func tearDown( ) async throws {
97- if isRunningInCI ( ) {
98- // Let the CI system deal with the databases, there's nothing we can or should do here.
99- } else {
100- try await tearDown ( databases: runningDatabases ( ) )
101- }
97+ try await tearDown ( databases: runningDatabases ( ) )
10298 }
10399
104100 func tearDown( databases: any Collection < Database > ) async throws {
@@ -142,20 +138,20 @@ actor DatabasePool {
142138 }
143139
144140 private func retainDatabase( ) async throws -> Database {
145- let start = Date ( )
146- print ( " ℹ️ \( #function) start " )
147- defer { print ( " ℹ️ \( #function) end " , Date ( ) . timeIntervalSince ( start) ) }
141+ // let start = Date()
142+ // print("ℹ️ \(#function) start")
143+ // defer { print("ℹ️ \(#function) end", Date().timeIntervalSince(start)) }
148144 var database = availableDatabases. randomElement ( )
149- var retry = 0
145+ // var retry = 0
150146 while database == nil {
151- defer { retry += 1 }
152- if retry > 0 && retry % 50 == 0 {
153- print ( " ℹ️ \( #function) available databases: \( availableDatabases. count) retry \( retry) " )
154- }
155- if retry >= 1000 {
156- throw " Retry count exceeded "
157- }
158- try await Task . sleep ( for: . milliseconds( 100 ) )
147+ // defer { retry += 1 }
148+ // if retry > 0 && retry % 50 == 0 {
149+ // print("ℹ️ \(#function) available databases: \(availableDatabases.count) retry \(retry)")
150+ // }
151+ // if retry >= 1000 {
152+ // throw "Retry count exceeded"
153+ // }
154+ try await Task . sleep ( for: . milliseconds( 10 ) )
159155 database = availableDatabases. randomElement ( )
160156 }
161157 guard let database else { fatalError ( " database cannot be nil here " ) }
@@ -199,7 +195,7 @@ extension DatabasePool.Database {
199195 // This is safeguard against accidental inheritance of setup in QueryPerformanceTests
200196 // and to ensure the database resetting cannot impact any other network hosts.
201197 if isRunningInCI ( ) {
202- self . host = " db- \( index) "
198+ self . host = " spi_test_ \( index) "
203199 self . port = 5432
204200 } else {
205201 self . host = Environment . get ( " DATABASE_HOST " ) !
@@ -223,7 +219,7 @@ extension DatabasePool.Database {
223219 print ( " ℹ️ \( #function) start " )
224220 defer { print ( " ℹ️ \( #function) end " , Date ( ) . timeIntervalSince ( start) ) }
225221 do {
226- try await _withDatabase ( " postgres " , details: connectionDetails, timeout: . seconds( 5 ) ) { // Connect to `postgres` db in order to reset the test db
222+ try await _withDatabase ( " postgres " , details: connectionDetails, timeout: . seconds( 10 ) ) { // Connect to `postgres` db in order to reset the test db
227223 let databaseName = Environment . get ( " DATABASE_NAME " ) !
228224 try await $0. query ( PostgresQuery ( unsafeSQL: " DROP DATABASE IF EXISTS \( databaseName) WITH (FORCE) " ) )
229225 try await $0. query ( PostgresQuery ( unsafeSQL: " CREATE DATABASE \( databaseName) " ) )
@@ -249,7 +245,7 @@ extension DatabasePool.Database {
249245 let original = Environment . get ( " DATABASE_NAME " ) !
250246 let snapshot = original + " _snapshot "
251247 do {
252- try await _withDatabase ( " postgres " , details: connectionDetails, timeout: . seconds( 5 ) ) { client in
248+ try await _withDatabase ( " postgres " , details: connectionDetails, timeout: . seconds( 10 ) ) { client in
253249 try await client. query ( PostgresQuery ( unsafeSQL: " DROP DATABASE IF EXISTS \( snapshot) WITH (FORCE) " ) )
254250 try await client. query ( PostgresQuery ( unsafeSQL: " CREATE DATABASE \( snapshot) TEMPLATE \( original) " ) )
255251 }
@@ -264,7 +260,7 @@ extension DatabasePool.Database {
264260 let snapshot = original + " _snapshot "
265261 // delete db and re-create from snapshot
266262 do {
267- try await _withDatabase ( " postgres " , details: details, timeout: . seconds( 1 ) ) { client in
263+ try await _withDatabase ( " postgres " , details: details, timeout: . seconds( 10 ) ) { client in
268264 try await client. query ( PostgresQuery ( unsafeSQL: " DROP DATABASE IF EXISTS \( original) WITH (FORCE) " ) )
269265 try await client. query ( PostgresQuery ( unsafeSQL: " CREATE DATABASE \( original) TEMPLATE \( snapshot) " ) )
270266 }
@@ -312,11 +308,19 @@ private func _withDatabase(_ databaseName: String,
312308
313309extension Environment {
314310 static var databasePoolSize : Int {
315- Environment . get ( " DATABASEPOOL_SIZE " ) . flatMap ( Int . init) ?? 4
311+ if isRunningInCI ( ) {
312+ 8
313+ } else {
314+ Environment . get ( " DATABASEPOOL_SIZE " ) . flatMap ( Int . init) ?? 4
315+ }
316316 }
317317
318318 static var databasePoolTearDown : Bool {
319- Environment . get ( " DATABASEPOOL_TEARDOWN " ) . flatMap ( \. asBool) ?? true
319+ if isRunningInCI ( ) {
320+ false
321+ } else {
322+ Environment . get ( " DATABASEPOOL_TEARDOWN " ) . flatMap ( \. asBool) ?? true
323+ }
320324 }
321325}
322326
0 commit comments