Skip to content

Commit b264d62

Browse files
authored
beta 1 (vapor#153)
1 parent 481c32d commit b264d62

File tree

7 files changed

+69
-87
lines changed

7 files changed

+69
-87
lines changed

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [tanner0101] # loganwright, joscdk
2+
open_collective: vapor

.github/workflows/test.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: test
2+
on:
3+
- pull_request
4+
jobs:
5+
xenial:
6+
container:
7+
image: vapor/swift:5.1-xenial
8+
services:
9+
psql:
10+
image: postgres
11+
ports:
12+
- 5432:5432
13+
env:
14+
POSTGRES_USER: vapor_username
15+
POSTGRES_DB: vapor_database
16+
POSTGRES_PASSWORD: vapor_password
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@master
20+
- run: swift test
21+
bionic:
22+
container:
23+
image: vapor/swift:5.1-bionic
24+
services:
25+
psql:
26+
image: postgres
27+
ports:
28+
- 5432:5432
29+
env:
30+
POSTGRES_USER: vapor_username
31+
POSTGRES_DB: vapor_database
32+
POSTGRES_PASSWORD: vapor_password
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@master
36+
- run: swift test
37+
thread:
38+
container:
39+
image: vapor/swift:5.1-bionic
40+
services:
41+
psql:
42+
image: postgres
43+
ports:
44+
- 5432:5432
45+
env:
46+
POSTGRES_USER: vapor_username
47+
POSTGRES_DB: vapor_database
48+
POSTGRES_PASSWORD: vapor_password
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@master
52+
- run: swift test --sanitize=thread

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ let package = Package(
88
],
99
dependencies: [
1010
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.0.0-alpha"),
11-
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.0.0-alpha"),
12-
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0-alpha"),
11+
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.0.0-beta"),
12+
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0-beta"),
1313
],
1414
targets: [
1515
.target(name: "PostgresKit", dependencies: ["AsyncKit", "PostgresNIO", "SQLKit"]),

Sources/PostgresKit/Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension ConnectionPool: SQLDatabase where Source.Connection: SQLDatabase {
2424

2525
extension ConnectionPool: PostgresClient where Source.Connection: PostgresClient {
2626
public var eventLoop: EventLoop {
27-
return self.source.eventLoop
27+
return self.eventLoopGroup.next()
2828
}
2929

3030
public func send(_ request: PostgresRequest) -> EventLoopFuture<Void> {

Sources/PostgresKit/PostgresConnectionSource.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
public struct PostgresConnectionSource: ConnectionPoolSource {
2-
public var eventLoop: EventLoop
32
public let configuration: PostgresConfiguration
43

5-
public init(configuration: PostgresConfiguration, on eventLoop: EventLoop) {
4+
public init(configuration: PostgresConfiguration) {
65
self.configuration = configuration
7-
self.eventLoop = eventLoop
86
}
97

10-
public func makeConnection() -> EventLoopFuture<PostgresConnection> {
8+
public func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
119
let address: SocketAddress
1210
do {
1311
address = try self.configuration.address()
1412
} catch {
15-
return self.eventLoop.makeFailedFuture(error)
13+
return eventLoop.makeFailedFuture(error)
1614
}
1715
return PostgresConnection.connect(
1816
to: address,
1917
tlsConfiguration: self.configuration.tlsConfiguration,
20-
on: self.eventLoop
18+
on: eventLoop
2119
).flatMap { conn in
2220
return conn.authenticate(
2321
username: self.configuration.username,

Tests/PostgresKitTests/PostgresKitTests.swift

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import SQLKitBenchmark
33
import XCTest
44

55
class PostgresKitTests: XCTestCase {
6-
private var group: EventLoopGroup!
6+
private var eventLoopGroup: EventLoopGroup!
77
private var eventLoop: EventLoop {
8-
return self.group.next()
8+
return self.eventLoopGroup.next()
99
}
1010

1111
override func setUp() {
12-
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
12+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
1313
}
1414

1515
override func tearDown() {
16-
XCTAssertNoThrow(try self.group.syncShutdownGracefully())
17-
self.group = nil
16+
XCTAssertNoThrow(try self.eventLoopGroup.syncShutdownGracefully())
17+
self.eventLoopGroup = nil
1818
}
1919

2020

@@ -27,11 +27,10 @@ class PostgresKitTests: XCTestCase {
2727

2828
func testPerformance() throws {
2929
let db = PostgresConnectionSource(
30-
configuration: .init(hostname: hostname, username: "vapor_username", password: "vapor_password", database: "vapor_database"),
31-
on: self.eventLoop
30+
configuration: .init(hostname: hostname, username: "vapor_username", password: "vapor_password", database: "vapor_database")
3231
)
33-
let pool = ConnectionPool(config: .init(maxConnections: 12), source: db)
34-
defer { try! pool.close().wait() }
32+
let pool = ConnectionPool(configuration: .init(maxConnections: 12), source: db, on: self.eventLoopGroup)
33+
defer { pool.shutdown() }
3534
self.measure {
3635
for _ in 1...100 {
3736
_ = try! pool.withConnection { conn in

circle.yml

-69
This file was deleted.

0 commit comments

Comments
 (0)