@@ -14,20 +14,15 @@ import (
14
14
// atomic access to the db. If anything fails in the middle of an `Update`
15
15
// function, then all the changes prior should be rolled back.
16
16
func TestKVStoreTxs (t * testing.T ) {
17
- ctx := context .Background ()
18
- tmpDir := t .TempDir ()
19
-
20
- db , err := NewBoltDB (tmpDir , "test.db" , nil )
21
- require .NoError (t , err )
22
- t .Cleanup (func () {
23
- _ = db .Close ()
24
- })
17
+ t .Parallel ()
25
18
19
+ ctx := context .Background ()
20
+ db := NewTestDB (t )
26
21
store := db .GetKVStores ("AutoFees" , [4 ]byte {1 , 1 , 1 , 1 }, "auto-fees" )
27
22
28
23
// Test that if an action fails midway through the transaction, then
29
24
// it is rolled back.
30
- err = store .Update (ctx , func (ctx context.Context , tx KVStoreTx ) error {
25
+ err : = store .Update (ctx , func (ctx context.Context , tx KVStoreTx ) error {
31
26
err := tx .Global ().Set (ctx , "test" , []byte {1 })
32
27
if err != nil {
33
28
return err
@@ -63,10 +58,14 @@ func TestKVStoreTxs(t *testing.T) {
63
58
// KV stores and the session feature level stores.
64
59
func TestTempAndPermStores (t * testing.T ) {
65
60
t .Run ("session level kv store" , func (t * testing.T ) {
61
+ t .Parallel ()
62
+
66
63
testTempAndPermStores (t , false )
67
64
})
68
65
69
66
t .Run ("session feature level kv store" , func (t * testing.T ) {
67
+ t .Parallel ()
68
+
70
69
testTempAndPermStores (t , true )
71
70
})
72
71
}
@@ -78,26 +77,21 @@ func TestTempAndPermStores(t *testing.T) {
78
77
// session level KV stores.
79
78
func testTempAndPermStores (t * testing.T , featureSpecificStore bool ) {
80
79
ctx := context .Background ()
81
- tmpDir := t .TempDir ()
82
80
83
81
var featureName string
84
82
if featureSpecificStore {
85
83
featureName = "auto-fees"
86
84
}
87
85
88
- store , err := NewBoltDB (tmpDir , "test.db" , nil )
89
- require .NoError (t , err )
90
- t .Cleanup (func () {
91
- _ = store .Close ()
92
- })
86
+ store := NewTestDB (t )
93
87
db := NewDB (store )
94
88
require .NoError (t , db .Start (ctx ))
95
89
96
90
kvstores := db .GetKVStores (
97
91
"test-rule" , [4 ]byte {1 , 1 , 1 , 1 }, featureName ,
98
92
)
99
93
100
- err = kvstores .Update (ctx , func (ctx context.Context ,
94
+ err : = kvstores .Update (ctx , func (ctx context.Context ,
101
95
tx KVStoreTx ) error {
102
96
103
97
// Set an item in the temp store.
@@ -168,14 +162,9 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
168
162
169
163
// TestKVStoreNameSpaces tests that the various name spaces are used correctly.
170
164
func TestKVStoreNameSpaces (t * testing.T ) {
165
+ t .Parallel ()
171
166
ctx := context .Background ()
172
- tmpDir := t .TempDir ()
173
-
174
- db , err := NewBoltDB (tmpDir , "test.db" , nil )
175
- require .NoError (t , err )
176
- t .Cleanup (func () {
177
- _ = db .Close ()
178
- })
167
+ db := NewTestDB (t )
179
168
180
169
var (
181
170
groupID1 = intToSessionID (1 )
@@ -191,7 +180,7 @@ func TestKVStoreNameSpaces(t *testing.T) {
191
180
rulesDB3 := db .GetKVStores ("test-rule" , groupID2 , "re-balance" )
192
181
193
182
// Test that the three ruleDBs share the same global space.
194
- err = rulesDB1 .Update (ctx , func (ctx context.Context ,
183
+ err : = rulesDB1 .Update (ctx , func (ctx context.Context ,
195
184
tx KVStoreTx ) error {
196
185
197
186
return tx .Global ().Set (
0 commit comments