From 10049182cc2318238c8b5c0b1ae5dc940d21e2a8 Mon Sep 17 00:00:00 2001 From: XuPeng-SH Date: Fri, 4 Aug 2023 23:33:37 +0800 Subject: [PATCH] update ut (#11042) Update UT to store test workspace under `/tmp/${username}-ut-workspace` Approved by: @LeftHandCold --- .../batchstoredriver/batchstore_test.go | 8 +-- .../engine/tae/logstore/store/store_test.go | 17 +++--- pkg/vm/engine/tae/rpc/rpc_test.go | 52 ++----------------- pkg/vm/engine/tae/testutils/helpers.go | 6 ++- 4 files changed, 21 insertions(+), 62 deletions(-) diff --git a/pkg/vm/engine/tae/logstore/driver/batchstoredriver/batchstore_test.go b/pkg/vm/engine/tae/logstore/driver/batchstoredriver/batchstore_test.go index 27acd83507e7..5a504a3d2c55 100644 --- a/pkg/vm/engine/tae/logstore/driver/batchstoredriver/batchstore_test.go +++ b/pkg/vm/engine/tae/logstore/driver/batchstoredriver/batchstore_test.go @@ -15,7 +15,6 @@ package batchstoredriver import ( - "os" "sync" "testing" @@ -28,10 +27,13 @@ import ( "github.com/stretchr/testify/assert" ) +const ( + Modulename = "batchstoredriver" +) + func initEnv(t *testing.T) *baseStore { - dir := "/tmp/logstore/teststore/batchstoredriver" + dir := testutils.InitTestEnv(Modulename, t) name := "mock" - os.RemoveAll(dir) cfg := &StoreCfg{ RotateChecker: NewMaxSizeRotateChecker(int(mpool.KB) * 3), } diff --git a/pkg/vm/engine/tae/logstore/store/store_test.go b/pkg/vm/engine/tae/logstore/store/store_test.go index 69c55d3b08ee..a8ff78b981df 100644 --- a/pkg/vm/engine/tae/logstore/store/store_test.go +++ b/pkg/vm/engine/tae/logstore/store/store_test.go @@ -16,26 +16,26 @@ package store import ( "math/rand" - "os" "strconv" "testing" // "net/http" // _ "net/http/pprof" - // "github.com/lni/vfs" - // "github.com/matrixorigin/matrixone/pkg/logservice" "github.com/matrixorigin/matrixone/pkg/common/mpool" "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/driver" "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/driver/batchstoredriver" "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils" - // "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/driver/logservicedriver" "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/entry" "github.com/stretchr/testify/assert" ) +const ( + ModuleName = "logstore" +) + // var buf []byte // func init() { // go http.ListenAndServe("0.0.0.0:6060", nil) @@ -47,9 +47,8 @@ import ( // } func newTestDriver(t *testing.T, size int) driver.Driver { - dir := "/tmp/logstore/teststore/store" - name := "mock" - os.RemoveAll(dir) + dir := testutils.InitTestEnv(ModuleName, t) + name := "test" cfg := &batchstoredriver.StoreCfg{ RotateChecker: batchstoredriver.NewMaxSizeRotateChecker(size), } @@ -59,8 +58,8 @@ func newTestDriver(t *testing.T, size int) driver.Driver { } func restartTestDriver(t *testing.T, size int) driver.Driver { - dir := "/tmp/logstore/teststore/store" - name := "mock" + dir := testutils.InitTestEnv(ModuleName, t) + name := "test" cfg := &batchstoredriver.StoreCfg{ RotateChecker: batchstoredriver.NewMaxSizeRotateChecker(size), } diff --git a/pkg/vm/engine/tae/rpc/rpc_test.go b/pkg/vm/engine/tae/rpc/rpc_test.go index 5269e9c7a91b..985ed478235a 100644 --- a/pkg/vm/engine/tae/rpc/rpc_test.go +++ b/pkg/vm/engine/tae/rpc/rpc_test.go @@ -16,8 +16,6 @@ package rpc import ( "context" - "os" - "path" "strconv" "sync" "testing" @@ -30,8 +28,6 @@ import ( "github.com/matrixorigin/matrixone/pkg/container/batch" "github.com/matrixorigin/matrixone/pkg/container/types" "github.com/matrixorigin/matrixone/pkg/container/vector" - "github.com/matrixorigin/matrixone/pkg/defines" - "github.com/matrixorigin/matrixone/pkg/fileservice" "github.com/matrixorigin/matrixone/pkg/pb/api" "github.com/matrixorigin/matrixone/pkg/pb/plan" "github.com/matrixorigin/matrixone/pkg/pb/txn" @@ -54,23 +50,9 @@ func TestHandle_HandleCommitPerformanceForS3Load(t *testing.T) { opts := config.WithLongScanAndCKPOpts(nil) ctx := context.Background() - //create file service; - //dir := testutils.GetDefaultTestPath(ModuleName, t) - dir := "/tmp/s3" - dir = path.Join(dir, "/local") - //if dir exists, remove it. - os.RemoveAll(dir) - c := fileservice.Config{ - Name: defines.LocalFileServiceName, - Backend: "DISK", - DataDir: dir, - } - //create dir; - fs, err := fileservice.NewFileService(ctx, c, nil) - assert.Nil(t, err) - opts.Fs = fs handle := mockTAEHandle(ctx, t, opts) defer handle.HandleClose(context.TODO()) + fs := handle.db.Opts.Fs IDAlloc := catalog.NewIDAllocator() schema := catalog.MockSchema(2, 1) @@ -228,23 +210,9 @@ func TestHandle_HandlePreCommitWriteS3(t *testing.T) { opts := config.WithLongScanAndCKPOpts(nil) ctx := context.Background() - //create file service; - //dir := testutils.GetDefaultTestPath(ModuleName, t) - dir := "/tmp/s3" - dir = path.Join(dir, "/local") - //if dir exists, remove it. - os.RemoveAll(dir) - c := fileservice.Config{ - Name: defines.LocalFileServiceName, - Backend: "DISK", - DataDir: dir, - } - //create dir; - fs, err := fileservice.NewFileService(ctx, c, nil) - assert.Nil(t, err) - opts.Fs = fs handle := mockTAEHandle(ctx, t, opts) defer handle.HandleClose(context.TODO()) + fs := handle.db.Opts.Fs IDAlloc := catalog.NewIDAllocator() schema := catalog.MockSchema(2, 1) @@ -260,7 +228,7 @@ func TestHandle_HandlePreCommitWriteS3(t *testing.T) { taeBats[3] = taeBats[3].CloneWindow(0, 10) //sort by primary key - _, err = mergesort.SortBlockColumns(taeBats[0].Vecs, 1, mocks.GetTestVectorPool()) + _, err := mergesort.SortBlockColumns(taeBats[0].Vecs, 1, mocks.GetTestVectorPool()) assert.Nil(t, err) _, err = mergesort.SortBlockColumns(taeBats[1].Vecs, 1, mocks.GetTestVectorPool()) assert.Nil(t, err) @@ -1741,20 +1709,6 @@ func TestApplyDeltaloc(t *testing.T) { opts := config.WithLongScanAndCKPOpts(nil) ctx := context.Background() - //create file service; - dir := "/tmp/s3" - dir = path.Join(dir, "/local") - //if dir exists, remove it. - os.RemoveAll(dir) - c := fileservice.Config{ - Name: defines.LocalFileServiceName, - Backend: "DISK", - DataDir: dir, - } - //create dir; - fs, err := fileservice.NewFileService(ctx, c, nil) - assert.Nil(t, err) - opts.Fs = fs h := mockTAEHandle(ctx, t, opts) defer h.HandleClose(context.TODO()) diff --git a/pkg/vm/engine/tae/testutils/helpers.go b/pkg/vm/engine/tae/testutils/helpers.go index 55ba6b91404a..66f1b6d7a03d 100644 --- a/pkg/vm/engine/tae/testutils/helpers.go +++ b/pkg/vm/engine/tae/testutils/helpers.go @@ -16,7 +16,9 @@ package testutils import ( "context" + "fmt" "os" + "os/user" "path/filepath" "testing" "time" @@ -57,7 +59,9 @@ func WaitChTimeout[T any]( } func GetDefaultTestPath(module string, t *testing.T) string { - return filepath.Join("/tmp", module, t.Name()) + usr, _ := user.Current() + dirName := fmt.Sprintf("%s-ut-workspace", usr.Username) + return filepath.Join("/tmp", dirName, module, t.Name()) } func MakeDefaultTestPath(module string, t *testing.T) string {