From 212cfe4aaa4dc09316f78abdbd5e593f66c419d4 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Tue, 12 Mar 2019 16:47:50 -0400 Subject: [PATCH 1/3] configure performance testing --- Tests/LinuxMain.swift | 3 +- .../PostgreSQLConnectionTests.swift | 20 +------------ .../PostgreSQLPerformanceTests.swift | 28 +++++++++++++++++++ circle.yml | 21 +++++++------- 4 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index b6cbdbeb..f5ecdc3f 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -2,5 +2,6 @@ import XCTest @testable import PostgreSQLTests XCTMain([ - testCase(PostgreSQLConnectionTests.allTests), + testCase(ConnectionTests.allTests), + testCase(PerformanceTests.allTests), ]) diff --git a/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift b/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift index baae5658..54f75d05 100644 --- a/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift +++ b/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift @@ -2,7 +2,7 @@ import SQLBenchmark import XCTest -class PostgreSQLConnectionTests: XCTestCase { +class ConnectionTests: XCTestCase { struct VersionMetadata: Codable { var version: String } @@ -621,24 +621,6 @@ class PostgreSQLConnectionTests: XCTestCase { } } - func testRangeSelectDecodePerformance() throws { - struct Series: Decodable { - var num: Int - } - - let conn = try PostgreSQLConnection.makeTest() - measure { - let decoder = PostgreSQLRowDecoder() - do { - try conn.simpleQuery("SELECT * FROM generate_series(1, 10000) num") { row in - _ = try decoder.decode(Series.self, from: row) - }.wait() - } catch { - XCTFail("\(error)") - } - } - } - func testClosureRetainCycle() throws { weak var connection: PostgreSQLConnection? let request: EventLoopFuture diff --git a/Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift b/Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift new file mode 100644 index 00000000..13d37636 --- /dev/null +++ b/Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift @@ -0,0 +1,28 @@ +@testable import PostgreSQL +import SQLBenchmark +import XCTest + +class PerformanceTests: XCTestCase { + + func testRangeSelectDecodePerformance() throws { + struct Series: Decodable { + var num: Int + } + + let conn = try PostgreSQLConnection.makeTest() + measure { + let decoder = PostgreSQLRowDecoder() + do { + try conn.simpleQuery("SELECT * FROM generate_series(1, 10000) num") { row in + _ = try decoder.decode(Series.self, from: row) + }.wait() + } catch { + XCTFail("\(error)") + } + } + } + + static var allTests = [ + ("testRangeSelectDecodePerformance", testRangeSelectDecodePerformance), + ] +} diff --git a/circle.yml b/circle.yml index 07be919a..2ee97a90 100644 --- a/circle.yml +++ b/circle.yml @@ -111,6 +111,14 @@ jobs: - run: name: Compile code with optimizations command: swift build -c release + linux-performance: + docker: + - image: vapor/swift:5.0 + steps: + - checkout + - run: + name: swift test + command: swift test -c release --filter "PostgreSQLTests.PerformanceTests" workflows: version: 2 tests: @@ -121,13 +129,6 @@ workflows: - 9-linux - 9-linux-fluent - linux-release - nightly: - triggers: - - schedule: - cron: "0 0 * * *" - filters: - branches: - only: - - master - jobs: - - linux +notify: + webhooks: + - url: https://bot-gh.vapor.codes/circle/result From 14b6b41fe7171d680134097986336a98f2a02992 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Wed, 13 Mar 2019 11:16:26 -0400 Subject: [PATCH 2/3] add -enable-testing --- Tests/LinuxMain.swift | 11 ++-- ...ctionTests.swift => ConnectionTests.swift} | 29 +---------- ...anceTests.swift => PerformanceTests.swift} | 8 +-- Tests/PostgreSQLTests/XCTestManifests.swift | 51 +++++++++++++++++++ circle.yml | 2 +- 5 files changed, 60 insertions(+), 41 deletions(-) rename Tests/PostgreSQLTests/{PostgreSQLConnectionTests.swift => ConnectionTests.swift} (95%) rename Tests/PostgreSQLTests/{PostgreSQLPerformanceTests.swift => PerformanceTests.swift} (69%) create mode 100644 Tests/PostgreSQLTests/XCTestManifests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index f5ecdc3f..6a64e185 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,7 +1,8 @@ import XCTest -@testable import PostgreSQLTests -XCTMain([ - testCase(ConnectionTests.allTests), - testCase(PerformanceTests.allTests), -]) +import PostgreSQLTests + +var tests = [XCTestCaseEntry]() +tests += PostgreSQLTests.__allTests() + +XCTMain(tests) diff --git a/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift b/Tests/PostgreSQLTests/ConnectionTests.swift similarity index 95% rename from Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift rename to Tests/PostgreSQLTests/ConnectionTests.swift index 54f75d05..c0eedabd 100644 --- a/Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift +++ b/Tests/PostgreSQLTests/ConnectionTests.swift @@ -97,7 +97,7 @@ class ConnectionTests: XCTestCase { } struct Hello: Codable, ReflectionDecodable, Equatable { - static func reflectDecoded() throws -> (PostgreSQLConnectionTests.Hello, PostgreSQLConnectionTests.Hello) { + static func reflectDecoded() throws -> (Hello, Hello) { return (.init(message: "0"), .init(message: "1")) } @@ -670,33 +670,6 @@ class ConnectionTests: XCTestCase { XCTAssertEqual(polygon.polygon.points[3].y, 200) }.wait() } - - static var allTests = [ - ("testBenchmark", testBenchmark), - ("testVersion", testVersion), - ("testSelectTypes", testSelectTypes), - ("testStruct", testStruct), - ("testNull", testNull), - ("testGH24", testGH24), - ("testURLParsing", testURLParsing), - ("testGH46", testGH46), - ("testDataDecoder", testDataDecoder), - ("testRowDecoder", testRowDecoder), - ("testRowCodableNested", testRowCodableNested), - ("testRowCodableEmptyKeyed", testRowCodableEmptyKeyed), - ("testRowCodableTypes", testRowCodableTypes), - ("testTimeTz", testTimeTz), - ("testListen", testListen), - ("testSum", testSum), - ("testOrderBy", testOrderBy), - ("testInvalidDate", testInvalidDate), - ("testEmptyArray", testEmptyArray), - ("testZeroNumeric", testZeroNumeric), - ("testNumericDecode", testNumericDecode), - ("testClosureRetainCycle", testClosureRetainCycle), - ("testGH125", testGH125), - ("testPolygon", testPolygon), - ] } extension PostgreSQLConnection { diff --git a/Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift b/Tests/PostgreSQLTests/PerformanceTests.swift similarity index 69% rename from Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift rename to Tests/PostgreSQLTests/PerformanceTests.swift index 13d37636..b05a9dc2 100644 --- a/Tests/PostgreSQLTests/PostgreSQLPerformanceTests.swift +++ b/Tests/PostgreSQLTests/PerformanceTests.swift @@ -3,7 +3,6 @@ import SQLBenchmark import XCTest class PerformanceTests: XCTestCase { - func testRangeSelectDecodePerformance() throws { struct Series: Decodable { var num: Int @@ -11,18 +10,13 @@ class PerformanceTests: XCTestCase { let conn = try PostgreSQLConnection.makeTest() measure { - let decoder = PostgreSQLRowDecoder() do { try conn.simpleQuery("SELECT * FROM generate_series(1, 10000) num") { row in - _ = try decoder.decode(Series.self, from: row) + _ = try conn.decode(Series.self, from: row, table: nil) }.wait() } catch { XCTFail("\(error)") } } } - - static var allTests = [ - ("testRangeSelectDecodePerformance", testRangeSelectDecodePerformance), - ] } diff --git a/Tests/PostgreSQLTests/XCTestManifests.swift b/Tests/PostgreSQLTests/XCTestManifests.swift new file mode 100644 index 00000000..bb4d9c70 --- /dev/null +++ b/Tests/PostgreSQLTests/XCTestManifests.swift @@ -0,0 +1,51 @@ +#if !canImport(ObjectiveC) +import XCTest + +extension ConnectionTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__ConnectionTests = [ + ("testBenchmark", testBenchmark), + ("testClosureRetainCycle", testClosureRetainCycle), + ("testDataDecoder", testDataDecoder), + ("testEmptyArray", testEmptyArray), + ("testGH125", testGH125), + ("testGH24", testGH24), + ("testGH46", testGH46), + ("testInvalidDate", testInvalidDate), + ("testListen", testListen), + ("testNull", testNull), + ("testNumericDecode", testNumericDecode), + ("testOrderBy", testOrderBy), + ("testPolygon", testPolygon), + ("testRowCodableEmptyKeyed", testRowCodableEmptyKeyed), + ("testRowCodableNested", testRowCodableNested), + ("testRowCodableTypes", testRowCodableTypes), + ("testRowDecoder", testRowDecoder), + ("testSelectTypes", testSelectTypes), + ("testStruct", testStruct), + ("testSum", testSum), + ("testTimeTz", testTimeTz), + ("testURLParsing", testURLParsing), + ("testVersion", testVersion), + ("testZeroNumeric", testZeroNumeric), + ] +} + +extension PerformanceTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__PerformanceTests = [ + ("testRangeSelectDecodePerformance", testRangeSelectDecodePerformance), + ] +} + +public func __allTests() -> [XCTestCaseEntry] { + return [ + testCase(ConnectionTests.__allTests__ConnectionTests), + testCase(PerformanceTests.__allTests__PerformanceTests), + ] +} +#endif diff --git a/circle.yml b/circle.yml index 2ee97a90..611f3d67 100644 --- a/circle.yml +++ b/circle.yml @@ -118,7 +118,7 @@ jobs: - checkout - run: name: swift test - command: swift test -c release --filter "PostgreSQLTests.PerformanceTests" + command: swift test -c release -Xswiftc -enable-testing --filter "PostgreSQLTests.PerformanceTests" workflows: version: 2 tests: From 398156692351c0ff4bd5f7444ccd61b24f40ef16 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Wed, 13 Mar 2019 11:20:54 -0400 Subject: [PATCH 3/3] use swift 4.1 + add psql to perf test --- circle.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 611f3d67..3b66a690 100644 --- a/circle.yml +++ b/circle.yml @@ -113,7 +113,13 @@ jobs: command: swift build -c release linux-performance: docker: - - image: vapor/swift:5.0 + - image: codevapor/swift:4.1 + - image: circleci/postgres:9 + name: psql + environment: + POSTGRES_USER: vapor_username + POSTGRES_DB: vapor_database + POSTGRES_PASSWORD: vapor_password steps: - checkout - run: