Skip to content

Commit

Permalink
Adopt the new AsyncQueue, remove dependency on all three Fluent dri…
Browse files Browse the repository at this point in the history
…vers, other cleanup (#7)

Changes:

- Adopters of this package are no longer forced to have all three of the
Fluent SQL database driver stacks (SQLite, Postgres, MySQL) in their
dependencies (although SwiftPM usually manages to avoid this problem on
its own); the tests instead will only use whichever drivers were
included at the time of the tests being built (defaults to none).
- `StoredJobState.completed` has been removed, since we never actually
used it. This helpfully improves the behavior of the `clear()` query.
- The queue driver now adopts the new `AsyncQueue` protocol and no
longer has to go back and forth between futures.
- The tests are now more comprehensive.
- Fixed another `Sendable` warning.
  • Loading branch information
gwynne authored Jun 14, 2024
1 parent c369658 commit 0ecd6fa
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 228 deletions.
102 changes: 98 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,101 @@ on:
push: { branches: [ main ] }

jobs:
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
api-breakage:
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
runs-on: ubuntu-latest
container: swift:noble
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
with: { 'fetch-depth': 0 }
- name: Run API breakage check
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
swift package diagnose-api-breaking-changes origin/main
linux-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
swift-image:
- swift:5.8-jammy
- swift:5.9-jammy
- swift:5.10-noble
- swiftlang/swift:nightly-6.0-jammy
- swiftlang/swift:nightly-main-jammy
include:
- sanitize: '--sanitize=thread'
- swift-image: swift:5.8-jammy
sanitize: ''
runs-on: ubuntu-latest
container: ${{ matrix.swift-image }}
services:
psql: { image: 'postgres:16', env: { POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database, POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 } }
mysql: { image: 'mysql:8', env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } }
timeout-minutes: 60
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests
env:
SANITIZE: ${{ matrix.sanitize }}
POSTGRES_HOST: psql
MYSQL_HOST: mysql
run: SWIFT_DETERMINISTIC_HASHING=1 swift test ${SANITIZE} --enable-code-coverage
- name: Upload coverage data
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}

macos-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
include:
- macos-version: macos-13
xcode-version: '~15.2'
- macos-version: macos-14
xcode-version: latest-stable
runs-on: ${{ matrix.macos-version }}
timeout-minutes: 60
steps:
- name: Select appropriate Xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Install and setup Postgres
run: |
export PATH="$(brew --prefix)/opt/postgresql@16/bin:$PATH" PGDATA=/tmp/vapor-postgres-test
(brew upgrade [email protected] || true) && (brew link --force --overwrite [email protected] || true)
(brew upgrade [email protected] || true) && (brew link --force --overwrite [email protected] || true)
(brew upgrade || true)
brew install --overwrite postgresql@16 && brew link --overwrite --force postgresql@16
initdb --locale=C --auth-host scram-sha-256 -U test_username --pwfile=<(echo test_password)
pg_ctl start --wait
PGPASSWORD=test_password createdb -w -U test_username -O test_username test_database
PGPASSWORD=test_password psql -U test_username -w test_database <<<"ALTER SCHEMA public OWNER TO test_username;"
- name: Install and setup MySQL
run: |
set -x
brew install mysql && brew services start mysql
sleep 5
mysql -uroot --batch <<-'SQL'
CREATE USER test_username@localhost IDENTIFIED BY 'test_password';
CREATE DATABASE test_database;
GRANT ALL PRIVILEGES ON test_database.* TO test_username@localhost;
SQL
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests
env:
POSTGRES_HOST: 127.0.0.1
MYSQL_HOST: 127.0.0.1
run: SWIFT_DETERMINISTIC_HASHING=1 swift test --sanitize=thread --enable-code-coverage
- name: Upload coverage data
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}
13 changes: 9 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.8
import PackageDescription
import class Foundation.ProcessInfo

let package = Package(
name: "QueuesFluentDriver",
Expand All @@ -14,11 +15,13 @@ let package = Package(
.package(url: "https://github.com/vapor/fluent.git", from: "4.10.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.30.0"),
.package(url: "https://github.com/vapor/queues.git", from: "1.13.0"),
.package(url: "https://github.com/vapor/queues.git", from: "1.15.0"),
.package(url: "https://github.com/vapor/console-kit.git", from: "4.14.3"),
] + (ProcessInfo.processInfo.environment["CI"] != nil ? [
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.7.1"),
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.9.1"),
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.5.0"),
],
] : []),
targets: [
.target(
name: "QueuesFluentDriver",
Expand All @@ -36,11 +39,13 @@ let package = Package(
name: "QueuesFluentDriverTests",
dependencies: [
.product(name: "XCTVapor", package: "vapor"),
.product(name: "ConsoleKitTerminal", package: "console-kit"),
.target(name: "QueuesFluentDriver"),
] + (ProcessInfo.processInfo.environment["CI"] != nil ? [
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
.product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
.target(name: "QueuesFluentDriver"),
],
] : []),
swiftSettings: swiftSettings
),
]
Expand Down
13 changes: 9 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.9
import PackageDescription
import class Foundation.ProcessInfo

let package = Package(
name: "QueuesFluentDriver",
Expand All @@ -17,11 +18,13 @@ let package = Package(
.package(url: "https://github.com/vapor/fluent.git", from: "4.10.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.30.0"),
.package(url: "https://github.com/vapor/queues.git", from: "1.13.0"),
.package(url: "https://github.com/vapor/queues.git", from: "1.15.0"),
.package(url: "https://github.com/vapor/console-kit.git", from: "4.14.3"),
] + (ProcessInfo.processInfo.environment["CI"] != nil ? [
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.7.1"),
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.9.1"),
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.5.0"),
],
] : []),
targets: [
.target(
name: "QueuesFluentDriver",
Expand All @@ -39,11 +42,13 @@ let package = Package(
name: "QueuesFluentDriverTests",
dependencies: [
.product(name: "XCTVapor", package: "vapor"),
.product(name: "ConsoleKitTerminal", package: "console-kit"),
.target(name: "QueuesFluentDriver"),
] + (ProcessInfo.processInfo.environment["CI"] != nil ? [
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
.product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
.target(name: "QueuesFluentDriver"),
],
] : []),
swiftSettings: swiftSettings
),
]
Expand Down
Loading

0 comments on commit 0ecd6fa

Please sign in to comment.