@@ -189,6 +189,7 @@ private final class BlockingAuxiliaryDriver: DatabaseDriver, @unchecked Sendable
189189 var functionsToReturn : [ RoutineInfo ] = [ ]
190190 var schemasToReturn : [ String ] = [ ]
191191
192+ let tablesGate = AsyncGate ( )
192193 let routinesGate = AsyncGate ( )
193194 let schemasGate = AsyncGate ( )
194195
@@ -214,7 +215,8 @@ private final class BlockingAuxiliaryDriver: DatabaseDriver, @unchecked Sendable
214215 }
215216
216217 func fetchTables( ) async throws -> [ TableInfo ] {
217- tablesToReturn
218+ await tablesGate. wait ( )
219+ return tablesToReturn
218220 }
219221
220222 func fetchColumns( table: String ) async throws -> [ ColumnInfo ] { [ ] }
@@ -368,16 +370,10 @@ struct SchemaServiceRoutinesTests {
368370 await service. load ( connectionId: connectionId, driver: driver, connection: connection)
369371 }
370372
371- var loadedTables : [ TableInfo ] = [ ]
372- for _ in 0 ..< 100 {
373- if case . loaded( let tables) = service. state ( for: connectionId) {
374- loadedTables = tables
375- break
376- }
377- await Task . yield ( )
378- }
373+ await driver. tablesGate. open ( )
374+ await waitForLoadedState ( service, connectionId: connectionId)
379375
380- #expect( loadedTables . map ( \. name) == [ " users " ] )
376+ #expect( service . tables ( for : connectionId ) . map ( \. name) == [ " users " ] )
381377 #expect( service. procedures ( for: connectionId) . isEmpty)
382378 #expect( service. functions ( for: connectionId) . isEmpty)
383379 #expect( service. schemas ( for: connectionId) . isEmpty)
@@ -391,6 +387,15 @@ struct SchemaServiceRoutinesTests {
391387 #expect( service. schemas ( for: connectionId) == [ " public " ] )
392388 }
393389
390+ private func waitForLoadedState( _ service: SchemaService , connectionId: UUID ) async {
391+ while true {
392+ if case . loaded = service. state ( for: connectionId) {
393+ return
394+ }
395+ await Task . yield ( )
396+ }
397+ }
398+
394399 @Test ( " reloadProcedures refreshes only procedures " )
395400 func reloadProceduresOnly( ) async {
396401 let service = SchemaService ( )
0 commit comments