Skip to content

Commit

Permalink
update ut (#11042)
Browse files Browse the repository at this point in the history
Update UT to store test workspace under `/tmp/${username}-ut-workspace`

Approved by: @LeftHandCold
  • Loading branch information
XuPeng-SH authored Aug 4, 2023
1 parent 0a28ba0 commit 1004918
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package batchstoredriver

import (
"os"
"sync"
"testing"

Expand All @@ -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),
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/vm/engine/tae/logstore/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
}
Expand All @@ -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),
}
Expand Down
52 changes: 3 additions & 49 deletions pkg/vm/engine/tae/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package rpc

import (
"context"
"os"
"path"
"strconv"
"sync"
"testing"
Expand All @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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())

Expand Down
6 changes: 5 additions & 1 deletion pkg/vm/engine/tae/testutils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package testutils

import (
"context"
"fmt"
"os"
"os/user"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1004918

Please sign in to comment.