From 2569a55f63f4ff3fc758ad545bd86718fc2ad817 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Tue, 9 Aug 2022 16:54:55 -0400 Subject: [PATCH] Make prefixes_test.go more resilient against garbage left by a prior crash. Also correct error logging. --- db/prefixes/prefixes_test.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/db/prefixes/prefixes_test.go b/db/prefixes/prefixes_test.go index 02672e8..590c5de 100644 --- a/db/prefixes/prefixes_test.go +++ b/db/prefixes/prefixes_test.go @@ -28,12 +28,25 @@ func testInit(filePath string) (*grocksdb.DB, [][]string, func(), *grocksdb.Colu columnFamily := records[0][0] records = records[1:] + cleanupFiles := func() { + err = os.RemoveAll("./tmp") + if err != nil { + log.Println(err) + } + } + // wOpts := grocksdb.NewDefaultWriteOptions() opts := grocksdb.NewDefaultOptions() opts.SetCreateIfMissing(true) db, err := grocksdb.OpenDb(opts, "tmp") if err != nil { 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) if err != nil { @@ -41,10 +54,7 @@ func testInit(filePath string) (*grocksdb.DB, [][]string, func(), *grocksdb.Colu } toDefer := func() { db.Close() - err = os.RemoveAll("./tmp") - if err != nil { - log.Println(err) - } + cleanupFiles() } return db, records, toDefer, handle @@ -101,7 +111,7 @@ func testGeneric(filePath string, prefix byte, numPartials int) func(*testing.T) log.Println(err) } 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) { t.Errorf("got: %+v, want: %+v\n", got, want)