From ab373a84edb26751586fb514f105ac4436a71939 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sat, 16 May 2020 08:47:21 -0500 Subject: [PATCH] Configure SQLiteConnectionSource with Database ID #55 --- .github/workflows/test.yml | 67 +++++++++++++------ .../FluentSQLiteDriverTests.swift | 11 ++- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cef21d4..dad379f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,26 +1,49 @@ -name: test -on: -- pull_request +name: Test Matrix +on: ['pull_request'] jobs: - fluent-sqlite-driver_macos: - runs-on: macos-latest - steps: - - run: sudo xcode-select -s /Applications/Xcode_11.4.app/Contents/Developer - - uses: actions/checkout@v2 - - run: xcrun swift test --enable-test-discovery --sanitize=thread - fluent-sqlite-driver_bionic: - container: - image: vapor/swift:5.2-bionic-ci + PR-tests-linux: + strategy: + fail-fast: false + matrix: + runner: [ + 'swift:5.2-xenial', 'swift:5.2-bionic', + 'swiftlang/swift:nightly-5.2-xenial', 'swiftlang/swift:nightly-5.2-bionic', + 'swiftlang/swift:nightly-5.3-xenial', 'swiftlang/swift:nightly-5.3-bionic', + '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' + ] + include: + - installcmd: 'apt-get -q update && apt-get -q install -y libsqlite3-dev' + - { 'runner': 'swiftlang/swift:nightly-master-centos8', 'installcmd': 'dnf install -y zlib-devel sqlite-devel' } + - { 'runner': 'swiftlang/swift:nightly-master-amazonlinux2', 'installcmd': 'yum install -y zlib-devel sqlite-devel' } + container: ${{ matrix.runner }} runs-on: ubuntu-latest steps: - - run: apt update -y; apt install -y libsqlite3-dev - - uses: actions/checkout@v2 - - run: swift test --enable-test-discovery --sanitize=thread - fluent-sqlite-driver_xenial: - container: - image: vapor/swift:5.2-xenial-ci - runs-on: ubuntu-latest + - name: Install dependencies + run: ${{ matrix.installcmd }} + - name: Update AmazonLinux2's too-old SQLite + if: ${{ endsWith(matrix.runner, 'amazonlinux2') }} + working-directory: /root + # Cribbed from the Fedora RPM, leaves out a lot. System's Tcl is too old to run SQLite's tests. + run: | + yum install -y file tcl-devel make + curl -L 'https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release' | tar xz && cd sqlite + export CFLAGS="-DSQLITE_DISABLE_DIRSYNC=1 -DSQLITE_SECURE_DELETE=1" + ./configure --prefix=/usr --libdir=/usr/lib64 --enable-fts3 --enable-all --with-tcl=/usr/lib64 + make all install + - name: Check out code + uses: actions/checkout@v2 + - name: Run tests with Thread Sanitizer + run: swift test --enable-test-discovery --sanitize=thread + PR-tests-macos: + runs-on: macos-latest steps: - - run: apt update -y; apt install -y libsqlite3-dev - - uses: actions/checkout@v2 - - run: swift test --enable-test-discovery --sanitize=thread + - name: Select latest available Xcode + uses: maxim-lobanov/setup-xcode@1.0 + with: { 'xcode-version': 'latest' } + - name: Check out code + uses: actions/checkout@v2 + - name: Run tests with Thread Sanitizer + run: swift test --enable-test-discovery --sanitize=thread diff --git a/Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift b/Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift index 08c5851..85835e3 100644 --- a/Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift +++ b/Tests/FluentSQLiteDriverTests/FluentSQLiteDriverTests.swift @@ -76,15 +76,18 @@ final class FluentSQLiteDriverTests: XCTestCase { var eventLoopGroup: EventLoopGroup! var dbs: Databases! + let benchmarkPath = FileManager.default.temporaryDirectory.appendingPathComponent("benchmark.sqlite").absoluteString + override func setUpWithError() throws { try super.setUpWithError() - + XCTAssert(isLoggingConfigured) self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) self.threadPool = .init(numberOfThreads: 2) self.threadPool.start() self.dbs = Databases(threadPool: self.threadPool, on: self.eventLoopGroup) self.dbs.use(.sqlite(.memory), as: .sqlite) + self.dbs.use(.sqlite(.file(self.benchmarkPath)), as: .benchmark) } override func tearDownWithError() throws { @@ -94,7 +97,7 @@ final class FluentSQLiteDriverTests: XCTestCase { self.threadPool = nil try self.eventLoopGroup.syncShutdownGracefully() self.eventLoopGroup = nil - + try super.tearDownWithError() } } @@ -107,3 +110,7 @@ let isLoggingConfigured: Bool = { } return true }() + +extension DatabaseID { + static let benchmark = DatabaseID(string: "benchmark") +}