forked from tendermint/tm-db
-
Notifications
You must be signed in to change notification settings - Fork 1
/
goleveldb_test.go
43 lines (36 loc) · 1011 Bytes
/
goleveldb_test.go
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
package db
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/syndtr/goleveldb/leveldb/opt"
)
func TestGoLevelDBNewGoLevelDB(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
defer cleanupDBDir("", name)
// Test we can't open the db twice for writing
wr1, err := NewGoLevelDB(name, "")
require.Nil(t, err)
_, err = NewGoLevelDB(name, "")
require.NotNil(t, err)
wr1.Close() // Close the db to release the lock
// Test we can open the db twice for reading only
ro1, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
require.Nil(t, err)
defer ro1.Close()
ro2, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
require.Nil(t, err)
defer ro2.Close()
}
func BenchmarkGoLevelDBRandomReadsWrites(b *testing.B) {
name := fmt.Sprintf("test_%x", randStr(12))
db, err := NewGoLevelDB(name, "")
if err != nil {
b.Fatal(err)
}
defer func() {
db.Close()
cleanupDBDir("", name)
}()
benchmarkRandomReadsWrites(b, db)
}