From 5ecb61e62ecdd0e3c21a712414678e643c80b6a6 Mon Sep 17 00:00:00 2001 From: Qiang Zhao Date: Fri, 18 Oct 2024 00:19:51 +0800 Subject: [PATCH] fix(server): fix wrong options for testing (#552) ## Motivation Using in-memory DB will not help validate re-open related logic. ## Modification - Using temp dir for re-open related testing. --- server/kv/db_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/kv/db_test.go b/server/kv/db_test.go index 56b85447..55a38ad3 100644 --- a/server/kv/db_test.go +++ b/server/kv/db_test.go @@ -16,6 +16,9 @@ package kv import ( "fmt" + "github.com/google/uuid" + "os" + "path" "testing" "github.com/stretchr/testify/assert" @@ -445,7 +448,11 @@ func TestDB_ReadCommitOffset(t *testing.T) { } func TestDb_UpdateTerm(t *testing.T) { - factory, err := NewPebbleKVFactory(testKVOptions) + factory, err := NewPebbleKVFactory(&FactoryOptions{ + InMemory: false, + CacheSizeMB: 1, + DataDir: path.Join(os.TempDir(), uuid.New().String()), + }) assert.NoError(t, err) db, err := NewDB(common.DefaultNamespace, 1, factory, 0, common.SystemClock) assert.NoError(t, err) @@ -471,7 +478,7 @@ func TestDb_UpdateTerm(t *testing.T) { term, _, err = db.ReadTerm() assert.NoError(t, err) - assert.Equal(t, wal.InvalidOffset, term) + assert.EqualValues(t, 1, term) assert.NoError(t, factory.Close()) } @@ -479,7 +486,11 @@ func TestDb_UpdateTerm(t *testing.T) { func TestDB_Delete(t *testing.T) { offset := int64(13) - factory, err := NewPebbleKVFactory(testKVOptions) + factory, err := NewPebbleKVFactory(&FactoryOptions{ + InMemory: false, + CacheSizeMB: 1, + DataDir: path.Join(os.TempDir(), uuid.New().String()), + }) assert.NoError(t, err) db, err := NewDB(common.DefaultNamespace, 1, factory, 0, common.SystemClock) assert.NoError(t, err)