File tree Expand file tree Collapse file tree 5 files changed +33
-22
lines changed
Sources/PostgresNIO/Connection Expand file tree Collapse file tree 5 files changed +33
-22
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,14 @@ jobs:
4444 container :
4545 image : vapor/swift:5.2
4646 services :
47- psql :
47+ postgres-a :
48+ image : postgres
49+ env :
50+ POSTGRES_USER : vapor_username
51+ POSTGRES_DB : vapor_database
52+ POSTGRES_PASSWORD : vapor_password
53+ postgres-b :
4854 image : postgres
49- ports :
50- - 5432:5432
5155 env :
5256 POSTGRES_USER : vapor_username
5357 POSTGRES_DB : vapor_database
6165 - run : swift test --enable-test-discovery --sanitize=thread
6266 working-directory : ./fluent-postgres-driver
6367 env :
64- POSTGRES_HOSTNAME : psql
68+ POSTGRES_HOSTNAME_A : postgres-a
69+ POSTGRES_HOSTNAME_B : postgres-b
70+
Original file line number Diff line number Diff line change 55DerivedData
66Package.resolved
77.swiftpm
8-
8+ Tests / LinuxMain.swift
Original file line number Diff line number Diff line change @@ -14,31 +14,23 @@ public final class PostgresConnection {
1414
1515 public var logger : Logger
1616
17- private var didClose : Bool
18-
1917 public var isClosed : Bool {
2018 return !self . channel. isActive
2119 }
2220
2321 init ( channel: Channel , logger: Logger ) {
2422 self . channel = channel
2523 self . logger = logger
26- self . didClose = false
2724 }
2825
2926 public func close( ) -> EventLoopFuture < Void > {
30- guard !self . didClose else {
31- return self . eventLoop. makeSucceededFuture ( ( ) )
32- }
33- self . didClose = true
34- if !self . isClosed {
35- return self . channel. close ( mode: . all)
36- } else {
27+ guard !self . isClosed else {
3728 return self . eventLoop. makeSucceededFuture ( ( ) )
3829 }
30+ return self . channel. close ( mode: . all)
3931 }
4032
4133 deinit {
42- assert ( self . didClose , " PostgresConnection deinitialized before being closed. " )
34+ assert ( self . isClosed , " PostgresConnection deinitialized before being closed. " )
4335 }
4436}
Original file line number Diff line number Diff line change 11import Logging
2- import PostgresNIO
2+ @ testable import PostgresNIO
33import XCTest
44import NIOTestUtils
55
@@ -914,6 +914,11 @@ final class PostgresNIOTests: XCTestCase {
914914 XCTFail ( " Should have failed " )
915915 } catch PostgresError . connectionClosed { }
916916 }
917+
918+ func testRemoteClose( ) throws {
919+ let conn = try PostgresConnection . test ( on: eventLoop) . wait ( )
920+ try conn. channel. close ( ) . wait ( )
921+ }
917922}
918923
919924func env( _ name: String ) -> String ? {
Original file line number Diff line number Diff line change @@ -4,11 +4,7 @@ import XCTest
44
55extension PostgresConnection {
66 static func address( ) throws -> SocketAddress {
7- #if os(Linux)
8- return try . makeAddressResolvingHost( " psql " , port: 5432 )
9- #else
10- return try . init( ipAddress: " 127.0.0.1 " , port: 5432 )
11- #endif
7+ try . makeAddressResolvingHost( hostname, port: 5432 )
128 }
139
1410 static func testUnauthenticated( on eventLoop: EventLoop ) -> EventLoopFuture < PostgresConnection > {
@@ -36,6 +32,18 @@ extension PostgresConnection {
3632 }
3733}
3834
35+ var hostname : String {
36+ if let hostname = env ( " POSTGRES_HOSTNAME " ) {
37+ return hostname
38+ } else {
39+ #if os(Linux)
40+ return " psql "
41+ #else
42+ return " localhost "
43+ #endif
44+ }
45+ }
46+
3947extension XCTestCase {
4048
4149 public static var shouldRunLongRunningTests : Bool {
You can’t perform that action at this time.
0 commit comments