Make prefixes_test.go more resilient against garbage left
by a prior crash. Also correct error logging.
This commit is contained in:
parent
ab2a39ac6c
commit
2569a55f63
1 changed files with 15 additions and 5 deletions
|
@ -28,12 +28,25 @@ func testInit(filePath string) (*grocksdb.DB, [][]string, func(), *grocksdb.Colu
|
||||||
columnFamily := records[0][0]
|
columnFamily := records[0][0]
|
||||||
records = records[1:]
|
records = records[1:]
|
||||||
|
|
||||||
|
cleanupFiles := func() {
|
||||||
|
err = os.RemoveAll("./tmp")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// wOpts := grocksdb.NewDefaultWriteOptions()
|
// wOpts := grocksdb.NewDefaultWriteOptions()
|
||||||
opts := grocksdb.NewDefaultOptions()
|
opts := grocksdb.NewDefaultOptions()
|
||||||
opts.SetCreateIfMissing(true)
|
opts.SetCreateIfMissing(true)
|
||||||
db, err := grocksdb.OpenDb(opts, "tmp")
|
db, err := grocksdb.OpenDb(opts, "tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
// Garbage might have been left behind by a prior crash.
|
||||||
|
cleanupFiles()
|
||||||
|
db, err = grocksdb.OpenDb(opts, "tmp")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handle, err := db.CreateColumnFamily(opts, columnFamily)
|
handle, err := db.CreateColumnFamily(opts, columnFamily)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,10 +54,7 @@ func testInit(filePath string) (*grocksdb.DB, [][]string, func(), *grocksdb.Colu
|
||||||
}
|
}
|
||||||
toDefer := func() {
|
toDefer := func() {
|
||||||
db.Close()
|
db.Close()
|
||||||
err = os.RemoveAll("./tmp")
|
cleanupFiles()
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return db, records, toDefer, handle
|
return db, records, toDefer, handle
|
||||||
|
@ -101,7 +111,7 @@ func testGeneric(filePath string, prefix byte, numPartials int) func(*testing.T)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(gotKey, wantKey) {
|
if !bytes.Equal(gotKey, wantKey) {
|
||||||
t.Errorf("gotKey: %+v, wantKey: %+v\n", got, want)
|
t.Errorf("gotKey: %+v, wantKey: %+v\n", gotKey, wantKey)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(got, want) {
|
||||||
t.Errorf("got: %+v, want: %+v\n", got, want)
|
t.Errorf("got: %+v, want: %+v\n", got, want)
|
||||||
|
|
Loading…
Add table
Reference in a new issue