Skip to content

Commit

Permalink
beta 1 (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 authored Oct 24, 2019
1 parent 481c32d commit b264d62
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [tanner0101] # loganwright, joscdk
open_collective: vapor
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: test
on:
- pull_request
jobs:
xenial:
container:
image: vapor/swift:5.1-xenial
services:
psql:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: vapor_username
POSTGRES_DB: vapor_database
POSTGRES_PASSWORD: vapor_password
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: swift test
bionic:
container:
image: vapor/swift:5.1-bionic
services:
psql:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: vapor_username
POSTGRES_DB: vapor_database
POSTGRES_PASSWORD: vapor_password
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: swift test
thread:
container:
image: vapor/swift:5.1-bionic
services:
psql:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: vapor_username
POSTGRES_DB: vapor_database
POSTGRES_PASSWORD: vapor_password
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: swift test --sanitize=thread
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.0.0-alpha"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.0.0-alpha"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0-alpha"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.0.0-beta"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0-beta"),
],
targets: [
.target(name: "PostgresKit", dependencies: ["AsyncKit", "PostgresNIO", "SQLKit"]),
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresKit/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension ConnectionPool: SQLDatabase where Source.Connection: SQLDatabase {

extension ConnectionPool: PostgresClient where Source.Connection: PostgresClient {
public var eventLoop: EventLoop {
return self.source.eventLoop
return self.eventLoopGroup.next()
}

public func send(_ request: PostgresRequest) -> EventLoopFuture<Void> {
Expand Down
10 changes: 4 additions & 6 deletions Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
public struct PostgresConnectionSource: ConnectionPoolSource {
public var eventLoop: EventLoop
public let configuration: PostgresConfiguration

public init(configuration: PostgresConfiguration, on eventLoop: EventLoop) {
public init(configuration: PostgresConfiguration) {
self.configuration = configuration
self.eventLoop = eventLoop
}

public func makeConnection() -> EventLoopFuture<PostgresConnection> {
public func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
let address: SocketAddress
do {
address = try self.configuration.address()
} catch {
return self.eventLoop.makeFailedFuture(error)
return eventLoop.makeFailedFuture(error)
}
return PostgresConnection.connect(
to: address,
tlsConfiguration: self.configuration.tlsConfiguration,
on: self.eventLoop
on: eventLoop
).flatMap { conn in
return conn.authenticate(
username: self.configuration.username,
Expand Down
17 changes: 8 additions & 9 deletions Tests/PostgresKitTests/PostgresKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import SQLKitBenchmark
import XCTest

class PostgresKitTests: XCTestCase {
private var group: EventLoopGroup!
private var eventLoopGroup: EventLoopGroup!
private var eventLoop: EventLoop {
return self.group.next()
return self.eventLoopGroup.next()
}

override func setUp() {
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
}

override func tearDown() {
XCTAssertNoThrow(try self.group.syncShutdownGracefully())
self.group = nil
XCTAssertNoThrow(try self.eventLoopGroup.syncShutdownGracefully())
self.eventLoopGroup = nil
}


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

func testPerformance() throws {
let db = PostgresConnectionSource(
configuration: .init(hostname: hostname, username: "vapor_username", password: "vapor_password", database: "vapor_database"),
on: self.eventLoop
configuration: .init(hostname: hostname, username: "vapor_username", password: "vapor_password", database: "vapor_database")
)
let pool = ConnectionPool(config: .init(maxConnections: 12), source: db)
defer { try! pool.close().wait() }
let pool = ConnectionPool(configuration: .init(maxConnections: 12), source: db, on: self.eventLoopGroup)
defer { pool.shutdown() }
self.measure {
for _ in 1...100 {
_ = try! pool.withConnection { conn in
Expand Down
69 changes: 0 additions & 69 deletions circle.yml

This file was deleted.

0 comments on commit b264d62

Please sign in to comment.