diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md deleted file mode 100644 index be1103d0..00000000 --- a/.github/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,59 +0,0 @@ -# Code of Conduct - -To be a truly great community, Swift.org needs to welcome developers from all walks of life, -with different backgrounds, and with a wide range of experience. A diverse and friendly -community will have more great ideas, more unique perspectives, and produce more great -code. We will work diligently to make the Swift community welcoming to everyone. - -To give clarity of what is expected of our members, Swift.org has adopted the code of conduct -defined by [contributor-covenant.org](https://www.contributor-covenant.org). This document is used across many open source -communities, and we think it articulates our values well. The full text is copied below: - -### Contributor Code of Conduct v1.3 - -As contributors and maintainers of this project, and in the interest of fostering an open and -welcoming community, we pledge to respect all people who contribute through reporting -issues, posting feature requests, updating documentation, submitting pull requests or patches, -and other activities. - -We are committed to making participation in this project a harassment-free experience for -everyone, regardless of level of experience, gender, gender identity and expression, sexual -orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or -nationality. - -Examples of unacceptable behavior by participants include: - -- The use of sexualized language or imagery -- Personal attacks -- Trolling or insulting/derogatory comments -- Public or private harassment -- Publishing other’s private information, such as physical or electronic addresses, without explicit permission -- Other unethical or unprofessional conduct - -Project maintainers have the right and responsibility to remove, edit, or reject comments, -commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of -Conduct, or to ban temporarily or permanently any contributor for other behaviors that they -deem inappropriate, threatening, offensive, or harmful. - -By adopting this Code of Conduct, project maintainers commit themselves to fairly and -consistently applying these principles to every aspect of managing this project. Project -maintainers who do not follow or enforce the Code of Conduct may be permanently removed -from the project team. - -This code of conduct applies both within project spaces and in public spaces when an -individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by -contacting a project maintainer at [conduct@swift.org](mailto:conduct@swift.org). All complaints will be reviewed and -investigated and will result in a response that is deemed necessary and appropriate to the -circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter -of an incident. - -*This policy is adapted from the Contributor Code of Conduct [version 1.3.0](http://contributor-covenant.org/version/1/3/0/).* - -### Reporting - -A working group of community members is committed to promptly addressing any [reported -issues](mailto:conduct@swift.org). Working group members are volunteers appointed by the project lead, with a -preference for individuals with varied backgrounds and perspectives. Membership is expected -to change regularly, and may grow or shrink. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49570cb3..4e4cfccb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,70 +1,132 @@ name: test -on: -- pull_request +on: + - pull_request +defaults: + run: + shell: bash jobs: - postgres-nio: - container: - image: vapor/swift:5.2 + dependents: + runs-on: ubuntu-latest services: - psql: - image: postgres - ports: - - 5432:5432 - env: + psql-a: + image: ${{ matrix.dbimage }} + env: POSTGRES_USER: vapor_username POSTGRES_DB: vapor_database POSTGRES_PASSWORD: vapor_password - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: swift test --enable-test-discovery --sanitize=thread - postgres-kit: - container: - image: vapor/swift:5.2 - services: - psql: - image: postgres - ports: - - 5432:5432 - env: + psql-b: + image: ${{ matrix.dbimage }} + env: POSTGRES_USER: vapor_username POSTGRES_DB: vapor_database POSTGRES_PASSWORD: vapor_password - runs-on: ubuntu-latest + container: swift:5.2-bionic + strategy: + fail-fast: false + matrix: + dbimage: + - postgres:12 + - postgres:11 + dependent: + - postgres-kit + - fluent-postgres-driver steps: - - run: git clone -b master https://github.com/vapor/postgres-kit.git - working-directory: ./ - - run: swift package edit postgres-nio --revision ${{ github.sha }} - working-directory: ./postgres-kit - - run: swift test --enable-test-discovery --sanitize=thread - working-directory: ./postgres-kit - env: - POSTGRES_HOSTNAME: psql - fluent-postgres-driver: - container: - image: vapor/swift:5.2 - services: - postgres-a: - image: postgres + - name: Check out package + uses: actions/checkout@v2 + with: + path: package + - name: Check out dependent + uses: actions/checkout@v2 + with: + repository: vapor/${{ matrix.dependent }} + path: dependent + - name: Use local package + run: swift package edit postgres-nio --path ../package + working-directory: dependent + - name: Run tests with Thread Sanitizer + run: swift test --enable-test-discovery --sanitize=thread + working-directory: dependent env: + POSTGRES_HOSTNAME: psql-a + POSTGRES_HOSTNAME_A: psql-a + POSTGRES_HOSTNAME_B: psql-b + LOG_LEVEL: notice + linux: + strategy: + fail-fast: false + matrix: + dbimage: + - postgres:12 + - postgres:11 + runner: + # 5.2 Stable + - swift:5.2-xenial + - swift:5.2-bionic + # 5.2 Unstable + - swiftlang/swift:nightly-5.2-xenial + - swiftlang/swift:nightly-5.2-bionic + # 5.3 Unstable + - swiftlang/swift:nightly-5.3-xenial + - swiftlang/swift:nightly-5.3-bionic + # Master Unsable + - swiftlang/swift:nightly-master-xenial + - swiftlang/swift:nightly-master-bionic + - swiftlang/swift:nightly-master-focal + - swiftlang/swift:nightly-master-centos8 + - swiftlang/swift:nightly-master-amazonlinux2 + container: ${{ matrix.runner }} + runs-on: ubuntu-latest + services: + psql: + image: ${{ matrix.dbimage }} + env: POSTGRES_USER: vapor_username POSTGRES_DB: vapor_database POSTGRES_PASSWORD: vapor_password - postgres-b: - image: postgres + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Run tests with Thread Sanitizer + run: swift test --enable-test-discovery --sanitize=thread env: - POSTGRES_USER: vapor_username - POSTGRES_DB: vapor_database - POSTGRES_PASSWORD: vapor_password - runs-on: ubuntu-latest + POSTGRES_HOSTNAME: psql + LOG_LEVEL: notice + macOS: + strategy: + fail-fast: false + matrix: + include: + - formula: postgresql@11 + datadir: postgresql@11 + - formula: postgresql@12 + datadir: postgres + runs-on: macos-latest steps: - - run: git clone -b master https://github.com/vapor/fluent-postgres-driver.git - working-directory: ./ - - run: swift package edit postgres-nio --revision ${{ github.sha }} - working-directory: ./fluent-postgres-driver - - run: swift test --enable-test-discovery --sanitize=thread - working-directory: ./fluent-postgres-driver - env: - POSTGRES_HOSTNAME_A: postgres-a - POSTGRES_HOSTNAME_B: postgres-b - + - name: Select latest available Xcode + uses: maxim-lobanov/setup-xcode@1.0 + with: + xcode-version: latest + - name: Replace Postgres install and start server + run: | + brew uninstall --force postgresql php && rm -rf /usr/local/{etc,var}/{postgres,pg}* + brew install ${{ matrix.formula }} && brew link --force ${{ matrix.formula }} + initdb --locale=C -E UTF-8 $(brew --prefix)/var/${{ matrix.datadir }} + brew services start ${{ matrix.formula }} + - name: Wait for server to be ready + run: until pg_isready; do sleep 1; done + timeout-minutes: 2 + - name: Setup users and databases for Postgres + run: | + createuser --createdb --login vapor_username + for db in vapor_database_{a,b}; do + createdb -Ovapor_username $db && psql $db <<<"ALTER SCHEMA public OWNER TO vapor_username;" + done + - name: Checkout code + uses: actions/checkout@v2 + - name: Run tests with Thread Sanitizer + run: swift test --enable-test-discovery --sanitize=thread + env: + POSTGRES_DATABASE: vapor_database_a + POSTGRES_DATABASE_A: vapor_database_a + POSTGRES_DATABASE_B: vapor_database_b + LOG_LEVEL: notice diff --git a/Tests/PostgresNIOTests/PerformanceTests.swift b/Tests/PostgresNIOTests/PerformanceTests.swift index 536fb632..a26748c4 100644 --- a/Tests/PostgresNIOTests/PerformanceTests.swift +++ b/Tests/PostgresNIOTests/PerformanceTests.swift @@ -268,7 +268,7 @@ private func prepareTableToMeasureSelectPerformance( file: StaticString = #file, line: UInt = #line ) throws { - XCTAssertEqual(rowCount % batchSize, 0, "`rowCount` must be a multiple of `batchSize`", file: file, line: line) + XCTAssertEqual(rowCount % batchSize, 0, "`rowCount` must be a multiple of `batchSize`", file: (file), line: line) let conn = try PostgresConnection.test(on: eventLoop).wait() defer { try! conn.close().wait() } diff --git a/Tests/PostgresNIOTests/Utilities.swift b/Tests/PostgresNIOTests/Utilities.swift index 1015b1f2..21e6a2fb 100644 --- a/Tests/PostgresNIOTests/Utilities.swift +++ b/Tests/PostgresNIOTests/Utilities.swift @@ -4,7 +4,7 @@ import XCTest extension PostgresConnection { static func address() throws -> SocketAddress { - try .makeAddressResolvingHost(hostname, port: 5432) + try .makeAddressResolvingHost( env("POSTGRES_HOSTNAME") ?? "localhost", port: 5432) } static func testUnauthenticated(on eventLoop: EventLoop) -> EventLoopFuture { @@ -18,9 +18,9 @@ extension PostgresConnection { static func test(on eventLoop: EventLoop) -> EventLoopFuture { return testUnauthenticated(on: eventLoop).flatMap { conn in return conn.authenticate( - username: "vapor_username", - database: "vapor_database", - password: "vapor_password" + username: env("POSTGRES_USERNAME") ?? "vapor_username", + database: env("POSTGRES_DATABASE") ?? "vapor_database", + password: env("POSTGRES_PASSWORD") ?? "vapor_password" ).map { return conn }.flatMapError { error in @@ -32,18 +32,6 @@ extension PostgresConnection { } } -var hostname: String { - if let hostname = env("POSTGRES_HOSTNAME") { - return hostname - } else { - #if os(Linux) - return "psql" - #else - return "localhost" - #endif - } -} - extension XCTestCase { public static var shouldRunLongRunningTests: Bool {