@@ -46,6 +46,44 @@ final class AsyncPostgresConnectionTests: XCTestCase {
4646 }
4747 }
4848
49+ func testSelectActiveConnection( ) async throws {
50+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
51+ defer { XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) ) }
52+ let eventLoop = eventLoopGroup. next ( )
53+
54+ let query : PostgresQuery = """
55+ SELECT
56+ pid
57+ ,datname
58+ ,usename
59+ ,application_name
60+ ,client_hostname
61+ ,client_port
62+ ,backend_start
63+ ,query_start
64+ ,query
65+ ,state
66+ FROM pg_stat_activity
67+ WHERE state = 'active';
68+ """
69+
70+ try await withTestConnection ( on: eventLoop) { connection in
71+ let rows = try await connection. query ( query, logger: . psqlTest)
72+ var counter = 0
73+
74+ for try await element in rows. decode ( ( Int, String, String, String, String? , Int, Date, Date, String, String) . self) {
75+ XCTAssertEqual ( element. 1 , env ( " POSTGRES_DB " ) ?? " localhost " )
76+ XCTAssertEqual ( element. 2 , env ( " POSTGRES_USER " ) ?? " test_username " )
77+
78+ XCTAssertEqual ( element. 8 , query. sql)
79+ XCTAssertEqual ( element. 9 , " active " )
80+ counter += 1
81+ }
82+
83+ XCTAssertGreaterThanOrEqual ( counter, 1 )
84+ }
85+ }
86+
4987 func testSelectTimeoutWhileLongRunningQuery( ) async throws {
5088 let eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
5189 defer { XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) ) }
@@ -273,7 +311,7 @@ extension XCTestCase {
273311 try await connection. close ( )
274312 return result
275313 } catch {
276- XCTFail ( " Unexpected error: \( error) " , file: file, line: line)
314+ XCTFail ( " Unexpected error: \( String ( reflecting : error) ) " , file: file, line: line)
277315 try await connection. close ( )
278316 throw error
279317 }
0 commit comments