This is a follow up to an earlier post. I don't know the proper etiquette to follow in these cases but thought I'd post in the Vapor category this time around considering the package/module involved.
I've read and re-read all the documentation I can find to help but I've reached a dead-end; How can I obtain an error, once client.query() eventually fails?!
@Test("Postgres Connection!", .timeLimit(.minutes(5)))
func postgresNio() async throws {
let nonRespondingServer = PostgresClient.Configuration(…)
let client = PostgresClient(configuration: nonRespondingServer, backgroundLogger: logger)
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
defer {
taskGroup.cancelAll()
}
taskGroup.addTask {
await client.run() // Only returns once the taskGroup is canceled;
}
// Fragile API!! Give it a few seconds for the client to setup. client.query() might hang otherwise!
try await Task.sleep(for: .seconds(5))
taskGroup.addTask {
logger.debug("Before query()")
try await client.query("Select nothing from nonExistingTable", logger: logger)
logger.debug("After query()") // ⬅️⚠️ Never reached!
}
do {
logger.debug("Await for ANY completing task")
try await taskGroup.next()
// Wait until *any* task in group returns/completes
// and rethrow if applicable;
logger.debug("A task completed!") // ⬅️⚠️ Never reached!
// `client.run()` will never complete (ok)
// but why is `client.query()` never completing?! Even in failure (!!)
} catch let e {
print("client.next() threw an error!") // ⬅️⚠️ Never reached!
taskGroup.cancelAll()
throw e
}
}
}
What I expect
- I expect
client.query()to log and THROW an error afterPostgresClient.options.connectTimeouthas elapsed without success.
What actually happens
client.query()does NOT throw if it can't reach the server;