@@ -3,33 +3,23 @@ import SQLKitBenchmark
3
3
import XCTest
4
4
5
5
class PostgresKitTests : XCTestCase {
6
- private var eventLoopGroup : EventLoopGroup !
7
- private var eventLoop : EventLoop {
8
- return self . eventLoopGroup. next ( )
9
- }
10
-
11
- override func setUp( ) {
12
- self . eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
13
- }
14
-
15
- override func tearDown( ) {
16
- XCTAssertNoThrow ( try self . eventLoopGroup. syncShutdownGracefully ( ) )
17
- self . eventLoopGroup = nil
18
- }
19
-
20
-
21
6
func testSQLKitBenchmark( ) throws {
22
7
let conn = try PostgresConnection . test ( on: self . eventLoop) . wait ( )
23
8
defer { try ! conn. close ( ) . wait ( ) }
24
- let benchmark = SQLBenchmarker ( on: conn)
9
+ conn. logger. logLevel = . trace
10
+ let benchmark = SQLBenchmarker ( on: conn. sql ( ) )
25
11
try benchmark. run ( )
26
12
}
27
13
28
14
func testPerformance( ) throws {
29
15
let db = PostgresConnectionSource (
30
16
configuration: . init( hostname: hostname, username: " vapor_username " , password: " vapor_password " , database: " vapor_database " )
31
17
)
32
- let pool = ConnectionPool ( configuration: . init( maxConnections: 12 ) , source: db, on: self . eventLoopGroup)
18
+ let pool = EventLoopGroupConnectionPool (
19
+ source: db,
20
+ maxConnectionsPerEventLoop: 2 ,
21
+ on: self . eventLoopGroup
22
+ )
33
23
defer { pool. shutdown ( ) }
34
24
self . measure {
35
25
for _ in 1 ... 100 {
@@ -43,35 +33,37 @@ class PostgresKitTests: XCTestCase {
43
33
func testCreateEnumWithBuilder( ) throws {
44
34
let conn = try PostgresConnection . test ( on: self . eventLoop) . wait ( )
45
35
defer { try ! conn. close ( ) . wait ( ) }
36
+ let db = conn. sql ( )
46
37
47
- try conn . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
48
- try conn . raw ( " DROP TYPE meal; " ) . run ( ) . wait ( )
38
+ try db . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
39
+ try db . raw ( " DROP TYPE meal; " ) . run ( ) . wait ( )
49
40
50
- try conn . create ( enum: SQLIdentifier ( " meal " ) , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
51
- try conn . raw ( " DROP TYPE meal; " ) . run ( ) . wait ( )
41
+ try db . create ( enum: SQLIdentifier ( " meal " ) , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
42
+ try db . raw ( " DROP TYPE meal; " ) . run ( ) . wait ( )
52
43
}
53
44
54
45
func testDropEnumWithBuilder( ) throws {
55
46
let conn = try PostgresConnection . test ( on: self . eventLoop) . wait ( )
56
47
defer { try ! conn. close ( ) . wait ( ) }
48
+ let db = conn. sql ( )
57
49
58
50
// these two should work even if the type does not exist
59
- try conn . drop ( type: " meal " ) . ifExists ( ) . run ( ) . wait ( )
60
- try conn . drop ( type: " meal " ) . ifExists ( ) . cascade ( ) . run ( ) . wait ( )
51
+ try db . drop ( type: " meal " ) . ifExists ( ) . run ( ) . wait ( )
52
+ try db . drop ( type: " meal " ) . ifExists ( ) . cascade ( ) . run ( ) . wait ( )
61
53
62
- try conn . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
63
- try conn . drop ( type: " meal " ) . ifExists ( ) . cascade ( ) . run ( ) . wait ( )
54
+ try db . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
55
+ try db . drop ( type: " meal " ) . ifExists ( ) . cascade ( ) . run ( ) . wait ( )
64
56
65
- try conn . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
66
- try conn . drop ( type: " meal " ) . run ( ) . wait ( )
57
+ try db . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
58
+ try db . drop ( type: " meal " ) . run ( ) . wait ( )
67
59
68
- try conn . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
69
- try conn . drop ( type: SQLIdentifier ( " meal " ) ) . run ( ) . wait ( )
60
+ try db . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
61
+ try db . drop ( type: SQLIdentifier ( " meal " ) ) . run ( ) . wait ( )
70
62
71
- try conn . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
72
- try conn . drop ( type: " meal " ) . cascade ( ) . run ( ) . wait ( )
63
+ try db . create ( enum: " meal " , cases: " breakfast " , " lunch " , " dinner " ) . run ( ) . wait ( )
64
+ try db . drop ( type: " meal " ) . cascade ( ) . run ( ) . wait ( )
73
65
}
74
-
66
+
75
67
func testLeak( ) throws {
76
68
struct Foo : Codable {
77
69
var id : String
@@ -87,8 +79,10 @@ class PostgresKitTests: XCTestCase {
87
79
let conn = try PostgresConnection . test ( on: self . eventLoop) . wait ( )
88
80
defer { try ! conn. close ( ) . wait ( ) }
89
81
90
- try conn. raw ( " DROP TABLE IF EXISTS foos " ) . run ( ) . wait ( )
91
- try conn. raw ( """
82
+ let db = conn. sql ( )
83
+
84
+ try db. raw ( " DROP TABLE IF EXISTS foos " ) . run ( ) . wait ( )
85
+ try db. raw ( """
92
86
CREATE TABLE foos (
93
87
id TEXT PRIMARY KEY,
94
88
description TEXT,
@@ -101,7 +95,7 @@ class PostgresKitTests: XCTestCase {
101
95
)
102
96
""" ) . run ( ) . wait ( )
103
97
defer {
104
- try ? conn . raw ( " DROP TABLE IF EXISTS foos " ) . run ( ) . wait ( )
98
+ try ? db . raw ( " DROP TABLE IF EXISTS foos " ) . run ( ) . wait ( )
105
99
}
106
100
107
101
for i in 0 ..< 5_000 {
@@ -115,9 +109,23 @@ class PostgresKitTests: XCTestCase {
115
109
modified_by: " test " ,
116
110
modified_at: Date ( )
117
111
)
118
- try conn . insert ( into: " foos " )
112
+ try db . insert ( into: " foos " )
119
113
. model ( zipcode)
120
114
. run ( ) . wait ( )
121
115
}
122
116
}
117
+
118
+ private var eventLoopGroup : EventLoopGroup !
119
+ private var eventLoop : EventLoop {
120
+ return self . eventLoopGroup. next ( )
121
+ }
122
+
123
+ override func setUp( ) {
124
+ self . eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
125
+ }
126
+
127
+ override func tearDown( ) {
128
+ XCTAssertNoThrow ( try self . eventLoopGroup. syncShutdownGracefully ( ) )
129
+ self . eventLoopGroup = nil
130
+ }
123
131
}
0 commit comments