File tree 5 files changed +33
-22
lines changed
Sources/PostgresNIO/Connection
5 files changed +33
-22
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,14 @@ jobs:
44
44
container :
45
45
image : vapor/swift:5.2
46
46
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 :
48
54
image : postgres
49
- ports :
50
- - 5432:5432
51
55
env :
52
56
POSTGRES_USER : vapor_username
53
57
POSTGRES_DB : vapor_database
61
65
- run : swift test --enable-test-discovery --sanitize=thread
62
66
working-directory : ./fluent-postgres-driver
63
67
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 5
5
DerivedData
6
6
Package.resolved
7
7
.swiftpm
8
-
8
+ Tests / LinuxMain.swift
Original file line number Diff line number Diff line change @@ -14,31 +14,23 @@ public final class PostgresConnection {
14
14
15
15
public var logger : Logger
16
16
17
- private var didClose : Bool
18
-
19
17
public var isClosed : Bool {
20
18
return !self . channel. isActive
21
19
}
22
20
23
21
init ( channel: Channel , logger: Logger ) {
24
22
self . channel = channel
25
23
self . logger = logger
26
- self . didClose = false
27
24
}
28
25
29
26
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 {
37
28
return self . eventLoop. makeSucceededFuture ( ( ) )
38
29
}
30
+ return self . channel. close ( mode: . all)
39
31
}
40
32
41
33
deinit {
42
- assert ( self . didClose , " PostgresConnection deinitialized before being closed. " )
34
+ assert ( self . isClosed , " PostgresConnection deinitialized before being closed. " )
43
35
}
44
36
}
Original file line number Diff line number Diff line change 1
1
import Logging
2
- import PostgresNIO
2
+ @ testable import PostgresNIO
3
3
import XCTest
4
4
import NIOTestUtils
5
5
@@ -914,6 +914,11 @@ final class PostgresNIOTests: XCTestCase {
914
914
XCTFail ( " Should have failed " )
915
915
} catch PostgresError . connectionClosed { }
916
916
}
917
+
918
+ func testRemoteClose( ) throws {
919
+ let conn = try PostgresConnection . test ( on: eventLoop) . wait ( )
920
+ try conn. channel. close ( ) . wait ( )
921
+ }
917
922
}
918
923
919
924
func env( _ name: String ) -> String ? {
Original file line number Diff line number Diff line change @@ -4,11 +4,7 @@ import XCTest
4
4
5
5
extension PostgresConnection {
6
6
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 )
12
8
}
13
9
14
10
static func testUnauthenticated( on eventLoop: EventLoop ) -> EventLoopFuture < PostgresConnection > {
@@ -36,6 +32,18 @@ extension PostgresConnection {
36
32
}
37
33
}
38
34
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
+
39
47
extension XCTestCase {
40
48
41
49
public static var shouldRunLongRunningTests : Bool {
You can’t perform that action at this time.
0 commit comments