@@ -3,28 +3,25 @@ import SQLite
3
3
4
4
class ConnectionPoolTests : SQLiteTestCase {
5
5
6
+ var pool : ConnectionPool !
7
+
6
8
override func setUp( ) {
7
- super. setUp ( )
9
+ let _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " )
10
+ pool = try ! ConnectionPool ( . URI( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " ) )
8
11
}
9
12
10
13
func testConnectionSetupClosures( ) {
11
14
12
- let _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " )
13
- let pool = try ! ConnectionPool ( . URI( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " ) )
14
-
15
15
pool. foreignKeys = true
16
16
pool. setup. append { try $0. execute ( " CREATE TABLE IF NOT EXISTS test(value INT) " ) }
17
17
18
- XCTAssertTrue ( try pool. readable. scalar ( " PRAGMA foreign_keys " ) as! Int64 == 1 )
18
+ XCTAssertTrue ( pool. readable. scalar ( " PRAGMA foreign_keys " ) as! Int64 == 1 )
19
19
try ! pool. writable. execute ( " INSERT INTO test(value) VALUES (1) " )
20
20
try ! pool. readable. execute ( " SELECT value FROM test " )
21
21
}
22
22
23
23
func testConcurrentAccess2( ) {
24
24
25
- let _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " )
26
- let pool = try ! ConnectionPool ( . URI( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " ) )
27
-
28
25
let conn = pool. writable
29
26
try ! conn. execute ( " DROP TABLE IF EXISTS test; CREATE TABLE test(id INTEGER PRIMARY KEY, name TEXT); " )
30
27
try ! conn. execute ( " DELETE FROM test " )
@@ -45,7 +42,7 @@ class ConnectionPoolTests : SQLiteTestCase {
45
42
46
43
print ( " started " , x)
47
44
48
- let conn = pool. readable
45
+ let conn = self . pool. readable
49
46
50
47
let stmt = try ! conn. prepare ( " SELECT name FROM test WHERE id = ? " )
51
48
var curr = stmt. scalar ( x) as! String
@@ -87,9 +84,6 @@ class ConnectionPoolTests : SQLiteTestCase {
87
84
88
85
func testConcurrentAccess( ) throws {
89
86
90
- let _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " )
91
- let pool = try ! ConnectionPool ( . URI( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " ) )
92
-
93
87
try ! pool. writable. execute ( " DROP TABLE IF EXISTS test; CREATE TABLE test(value); " )
94
88
try ! pool. writable. run ( " INSERT INTO test(value) VALUES(?) " , 0 )
95
89
@@ -102,7 +96,7 @@ class ConnectionPoolTests : SQLiteTestCase {
102
96
103
97
while !finished {
104
98
105
- let val = pool. readable. scalar ( " SELECT value FROM test " )
99
+ let val = self . pool. readable. scalar ( " SELECT value FROM test " )
106
100
assert ( val != nil , " DB query returned nil result set " )
107
101
108
102
}
@@ -129,9 +123,6 @@ class ConnectionPoolTests : SQLiteTestCase {
129
123
130
124
func testAutoRelease( ) {
131
125
132
- let _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " )
133
- let pool = try ! ConnectionPool ( . URI( " \( NSTemporaryDirectory ( ) ) /SQLite.swift Pool Tests.sqlite " ) )
134
-
135
126
do {
136
127
try ! pool. readable. execute ( " SELECT 1 " )
137
128
}
0 commit comments