Skip to content

Commit 5088dcb

Browse files
authored
configure performance testing (#133)
* configure performance testing * add -enable-testing * use swift 4.1 + add psql to perf test
1 parent 4d99693 commit 5088dcb

File tree

5 files changed

+98
-61
lines changed

5 files changed

+98
-61
lines changed

Tests/LinuxMain.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import XCTest
2-
@testable import PostgreSQLTests
32

4-
XCTMain([
5-
testCase(PostgreSQLConnectionTests.allTests),
6-
])
3+
import PostgreSQLTests
4+
5+
var tests = [XCTestCaseEntry]()
6+
tests += PostgreSQLTests.__allTests()
7+
8+
XCTMain(tests)

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift renamed to Tests/PostgreSQLTests/ConnectionTests.swift

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import SQLBenchmark
33
import XCTest
44

5-
class PostgreSQLConnectionTests: XCTestCase {
5+
class ConnectionTests: XCTestCase {
66
struct VersionMetadata: Codable {
77
var version: String
88
}
@@ -97,7 +97,7 @@ class PostgreSQLConnectionTests: XCTestCase {
9797
}
9898

9999
struct Hello: Codable, ReflectionDecodable, Equatable {
100-
static func reflectDecoded() throws -> (PostgreSQLConnectionTests.Hello, PostgreSQLConnectionTests.Hello) {
100+
static func reflectDecoded() throws -> (Hello, Hello) {
101101
return (.init(message: "0"), .init(message: "1"))
102102
}
103103

@@ -621,24 +621,6 @@ class PostgreSQLConnectionTests: XCTestCase {
621621
}
622622
}
623623

624-
func testRangeSelectDecodePerformance() throws {
625-
struct Series: Decodable {
626-
var num: Int
627-
}
628-
629-
let conn = try PostgreSQLConnection.makeTest()
630-
measure {
631-
let decoder = PostgreSQLRowDecoder()
632-
do {
633-
try conn.simpleQuery("SELECT * FROM generate_series(1, 10000) num") { row in
634-
_ = try decoder.decode(Series.self, from: row)
635-
}.wait()
636-
} catch {
637-
XCTFail("\(error)")
638-
}
639-
}
640-
}
641-
642624
func testClosureRetainCycle() throws {
643625
weak var connection: PostgreSQLConnection?
644626
let request: EventLoopFuture<Void>
@@ -688,33 +670,6 @@ class PostgreSQLConnectionTests: XCTestCase {
688670
XCTAssertEqual(polygon.polygon.points[3].y, 200)
689671
}.wait()
690672
}
691-
692-
static var allTests = [
693-
("testBenchmark", testBenchmark),
694-
("testVersion", testVersion),
695-
("testSelectTypes", testSelectTypes),
696-
("testStruct", testStruct),
697-
("testNull", testNull),
698-
("testGH24", testGH24),
699-
("testURLParsing", testURLParsing),
700-
("testGH46", testGH46),
701-
("testDataDecoder", testDataDecoder),
702-
("testRowDecoder", testRowDecoder),
703-
("testRowCodableNested", testRowCodableNested),
704-
("testRowCodableEmptyKeyed", testRowCodableEmptyKeyed),
705-
("testRowCodableTypes", testRowCodableTypes),
706-
("testTimeTz", testTimeTz),
707-
("testListen", testListen),
708-
("testSum", testSum),
709-
("testOrderBy", testOrderBy),
710-
("testInvalidDate", testInvalidDate),
711-
("testEmptyArray", testEmptyArray),
712-
("testZeroNumeric", testZeroNumeric),
713-
("testNumericDecode", testNumericDecode),
714-
("testClosureRetainCycle", testClosureRetainCycle),
715-
("testGH125", testGH125),
716-
("testPolygon", testPolygon),
717-
]
718673
}
719674

720675
extension PostgreSQLConnection {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@testable import PostgreSQL
2+
import SQLBenchmark
3+
import XCTest
4+
5+
class PerformanceTests: XCTestCase {
6+
func testRangeSelectDecodePerformance() throws {
7+
struct Series: Decodable {
8+
var num: Int
9+
}
10+
11+
let conn = try PostgreSQLConnection.makeTest()
12+
measure {
13+
do {
14+
try conn.simpleQuery("SELECT * FROM generate_series(1, 10000) num") { row in
15+
_ = try conn.decode(Series.self, from: row, table: nil)
16+
}.wait()
17+
} catch {
18+
XCTFail("\(error)")
19+
}
20+
}
21+
}
22+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#if !canImport(ObjectiveC)
2+
import XCTest
3+
4+
extension ConnectionTests {
5+
// DO NOT MODIFY: This is autogenerated, use:
6+
// `swift test --generate-linuxmain`
7+
// to regenerate.
8+
static let __allTests__ConnectionTests = [
9+
("testBenchmark", testBenchmark),
10+
("testClosureRetainCycle", testClosureRetainCycle),
11+
("testDataDecoder", testDataDecoder),
12+
("testEmptyArray", testEmptyArray),
13+
("testGH125", testGH125),
14+
("testGH24", testGH24),
15+
("testGH46", testGH46),
16+
("testInvalidDate", testInvalidDate),
17+
("testListen", testListen),
18+
("testNull", testNull),
19+
("testNumericDecode", testNumericDecode),
20+
("testOrderBy", testOrderBy),
21+
("testPolygon", testPolygon),
22+
("testRowCodableEmptyKeyed", testRowCodableEmptyKeyed),
23+
("testRowCodableNested", testRowCodableNested),
24+
("testRowCodableTypes", testRowCodableTypes),
25+
("testRowDecoder", testRowDecoder),
26+
("testSelectTypes", testSelectTypes),
27+
("testStruct", testStruct),
28+
("testSum", testSum),
29+
("testTimeTz", testTimeTz),
30+
("testURLParsing", testURLParsing),
31+
("testVersion", testVersion),
32+
("testZeroNumeric", testZeroNumeric),
33+
]
34+
}
35+
36+
extension PerformanceTests {
37+
// DO NOT MODIFY: This is autogenerated, use:
38+
// `swift test --generate-linuxmain`
39+
// to regenerate.
40+
static let __allTests__PerformanceTests = [
41+
("testRangeSelectDecodePerformance", testRangeSelectDecodePerformance),
42+
]
43+
}
44+
45+
public func __allTests() -> [XCTestCaseEntry] {
46+
return [
47+
testCase(ConnectionTests.__allTests__ConnectionTests),
48+
testCase(PerformanceTests.__allTests__PerformanceTests),
49+
]
50+
}
51+
#endif

circle.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ jobs:
111111
- run:
112112
name: Compile code with optimizations
113113
command: swift build -c release
114+
linux-performance:
115+
docker:
116+
- image: codevapor/swift:4.1
117+
- image: circleci/postgres:9
118+
name: psql
119+
environment:
120+
POSTGRES_USER: vapor_username
121+
POSTGRES_DB: vapor_database
122+
POSTGRES_PASSWORD: vapor_password
123+
steps:
124+
- checkout
125+
- run:
126+
name: swift test
127+
command: swift test -c release -Xswiftc -enable-testing --filter "PostgreSQLTests.PerformanceTests"
114128
workflows:
115129
version: 2
116130
tests:
@@ -121,13 +135,6 @@ workflows:
121135
- 9-linux
122136
- 9-linux-fluent
123137
- linux-release
124-
nightly:
125-
triggers:
126-
- schedule:
127-
cron: "0 0 * * *"
128-
filters:
129-
branches:
130-
only:
131-
- master
132-
jobs:
133-
- linux
138+
notify:
139+
webhooks:
140+
- url: https://bot-gh.vapor.codes/circle/result

0 commit comments

Comments
 (0)