-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSQLBenchmarker.swift
More file actions
81 lines (72 loc) · 2.58 KB
/
Copy pathSQLBenchmarker.swift
File metadata and controls
81 lines (72 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Logging
import NIOCore
import SQLKit
import XCTest
public final class SQLBenchmarker: Sendable {
let database: any SQLDatabase
public init(on database: any SQLDatabase) {
self.database = database
}
public func runAllTests() async throws {
try await self.testPlanets()
try await self.testCodable()
try await self.testEnum()
if self.database.dialect.name != "generic" {
try await self.testUpserts()
try await self.testUnions()
try await self.testJSONPaths()
}
}
@available(*, deprecated, renamed: "runAllTests()", message: "Use `runAllTests()` instead.")
public func testAll() throws {
try database.eventLoop.makeFutureWithTask { try await self.runAllTests() }.wait()
}
@available(*, deprecated, renamed: "runAllTests()", message: "Use `runAllTests()` instead.")
public func run() throws {
try self.testAll()
}
func runTest(
_ name: String = #function,
_ test: (any SQLDatabase) async throws -> ()
) async rethrows {
self.database.logger.notice("[SQLBenchmark] Running \(name)...")
try await test(self.database)
}
}
func XCTAssertEqualAsync<T>(
_ expression1: @autoclosure () async throws -> T,
_ expression2: @autoclosure () async throws -> T,
_ message: @autoclosure () -> String = "",
file: StaticString = #filePath, line: UInt = #line
) async where T: Equatable {
do {
let expr1 = try await expression1(), expr2 = try await expression2()
return XCTAssertEqual(expr1, expr2, message(), file: file, line: line)
} catch {
return XCTAssertEqual(try { () -> Bool in throw error }(), false, message(), file: file, line: line)
}
}
func XCTAssertThrowsErrorAsync<T>(
_ expression: @autoclosure () async throws -> T,
_ message: @autoclosure () -> String = "",
file: StaticString = #filePath, line: UInt = #line,
_ callback: (any Error) -> Void = { _ in }
) async {
do {
_ = try await expression()
XCTAssertThrowsError({}(), message(), file: file, line: line, callback)
} catch {
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line, callback)
}
}
func XCTAssertNoThrowAsync<T>(
_ expression: @autoclosure () async throws -> T,
_ message: @autoclosure () -> String = "",
file: StaticString = #filePath, line: UInt = #line
) async {
do {
_ = try await expression()
} catch {
XCTAssertNoThrow(try { throw error }(), message(), file: file, line: line)
}
}