Skip to content

Commit d2d9e8c

Browse files
committed
add serial bind test; related to #20
1 parent cd694bb commit d2d9e8c

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Sources/NIOPostgres/Connection/PostgresConnection.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public final class PostgresConnection {
1919
}
2020

2121
public func close() -> EventLoopFuture<Void> {
22+
guard self.channel.isActive else {
23+
return self.eventLoop.makeSucceededFuture(())
24+
}
2225
return self.channel.close(mode: .all)
2326
}
2427

Tests/NIOPostgresTests/NIOPostgresTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ final class NIOPostgresTests: XCTestCase {
233233
}
234234
}
235235

236+
/// https://github.com/vapor/nio-postgres/issues/20
237+
func testBindInteger() throws {
238+
let conn = try PostgresConnection.test(on: eventLoop).wait()
239+
defer { try! conn.close().wait() }
240+
_ = try conn.simpleQuery("drop table if exists person;").wait()
241+
_ = try conn.simpleQuery("create table person(id serial primary key, first_name text, last_name text);").wait()
242+
defer { _ = try! conn.simpleQuery("drop table person;").wait() }
243+
let id = PostgresData(int32: 5)
244+
_ = try conn.query("SELECT id, first_name, last_name FROM person WHERE id = $1", [id]).wait()
245+
}
246+
236247
func testRemoteTLSServer() throws {
237248
let url = "postgres://uymgphwj:[email protected]:5432/uymgphwj"
238249
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)

Tests/NIOPostgresTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extension NIOPostgresTests {
66
// `swift test --generate-linuxmain`
77
// to regenerate.
88
static let __allTests__NIOPostgresTests = [
9+
("testBindInteger", testBindInteger),
910
("testConnectAndClose", testConnectAndClose),
1011
("testDates", testDates),
1112
("testIntegers", testIntegers),

0 commit comments

Comments
 (0)