diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..0a22eec5 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [tanner0101] # loganwright, joscdk +open_collective: vapor diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..14930424 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/Package.swift b/Package.swift index 13a9e7bd..a6ed8c4e 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]), diff --git a/Sources/PostgresKit/Extensions.swift b/Sources/PostgresKit/Extensions.swift index a8097cf5..2b4332fd 100644 --- a/Sources/PostgresKit/Extensions.swift +++ b/Sources/PostgresKit/Extensions.swift @@ -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 { diff --git a/Sources/PostgresKit/PostgresConnectionSource.swift b/Sources/PostgresKit/PostgresConnectionSource.swift index 0336f206..3a9d68f5 100644 --- a/Sources/PostgresKit/PostgresConnectionSource.swift +++ b/Sources/PostgresKit/PostgresConnectionSource.swift @@ -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 { + public func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture { 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, diff --git a/Tests/PostgresKitTests/PostgresKitTests.swift b/Tests/PostgresKitTests/PostgresKitTests.swift index dbead583..9bf6e400 100644 --- a/Tests/PostgresKitTests/PostgresKitTests.swift +++ b/Tests/PostgresKitTests/PostgresKitTests.swift @@ -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 } @@ -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 diff --git a/circle.yml b/circle.yml deleted file mode 100644 index af75a593..00000000 --- a/circle.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 - -jobs: - 11-bionic: - docker: - - image: swift:5.0-bionic - - image: circleci/postgres:11 - name: psql - environment: - POSTGRES_USER: vapor_username - POSTGRES_DB: vapor_database - POSTGRES_PASSWORD: vapor_password - steps: - - checkout - - run: swift build - - run: swift test - 10-bionic: - docker: - - image: swift:5.0-bionic - - image: circleci/postgres:10 - name: psql - environment: - POSTGRES_USER: vapor_username - POSTGRES_DB: vapor_database - POSTGRES_PASSWORD: vapor_password - steps: - - checkout - - run: swift build - - run: swift test - 9-bionic: - docker: - - image: swift:5.0-bionic - - image: circleci/postgres:9 - name: psql - environment: - POSTGRES_USER: vapor_username - POSTGRES_DB: vapor_database - POSTGRES_PASSWORD: vapor_password - steps: - - checkout - - run: swift build - - run: swift test - linux-release: - docker: - - image: swift:5.0-bionic - steps: - - checkout - - run: swift build -c release - linux-performance: - docker: - - image: swift:5.0-bionic - - image: circleci/postgres:11 - name: psql - environment: - POSTGRES_USER: vapor_username - POSTGRES_DB: vapor_database - POSTGRES_PASSWORD: vapor_password - steps: - - checkout - - run: swift test -c release -workflows: - version: 2 - tests: - jobs: - - 11-bionic - - 10-bionic - # - 9-bionic - - linux-release - - linux-performance