Skip to content

Commit

Permalink
*: use the same path for tests (#8603)
Browse files Browse the repository at this point in the history
ref #7969

Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] authored Sep 12, 2024
1 parent f6ec3f3 commit e9714b6
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 18 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ CLEAN_UT_BINARY := find . -name '*.test.bin'| xargs rm -f

clean-test:
# Cleaning test tmp...
rm -rf /tmp/test_pd*
rm -rf /tmp/pd-tests*
rm -rf /tmp/test_etcd*
rm -rf /tmp/pd_tests*
rm -f $(REAL_CLUSTER_TEST_PATH)/playground.log
go clean -testcache
@$(CLEAN_UT_BINARY)
Expand Down
3 changes: 2 additions & 1 deletion pkg/mcs/scheduling/server/rule/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -83,7 +84,7 @@ func prepare(t require.TestingT) (context.Context, *clientv3.Client, func()) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
cfg := etcdutil.NewTestSingleConfig()
cfg.Dir = os.TempDir() + "/test_etcd"
cfg.Dir = filepath.Join(os.TempDir(), "/pd_tests")
os.RemoveAll(cfg.Dir)
etcd, err := embed.StartEtcd(cfg)
re.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/etcdutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewTestSingleConfig() *embed.Config {
}

func genRandName() string {
return "test_etcd_" + strconv.FormatInt(time.Now().UnixNano(), 10)
return "pd" + strconv.FormatInt(time.Now().UnixNano(), 10)
}

// NewTestEtcdCluster is used to create a etcd cluster for the unit test purpose.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func CleanServer(dataDir string) {
// InitTempFileLogger initializes the logger and redirects the log output to a temporary file.
func InitTempFileLogger(level string) (fname string) {
cfg := &log.Config{}
f, _ := os.CreateTemp(os.TempDir(), "pd_tests")
f, _ := os.CreateTemp("", "pd_tests")
fname = f.Name()
f.Close()
cfg.File.Filename = fname
Expand Down
5 changes: 3 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -290,8 +291,8 @@ func TestCheckClusterID(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfgs := NewTestMultiConfig(assertutil.CheckerWithNilAssert(re), 2)
for i, cfg := range cfgs {
cfg.DataDir = fmt.Sprintf("/tmp/test_pd_check_clusterID_%d", i)
for _, cfg := range cfgs {
cfg.DataDir, _ = os.MkdirTemp("", "pd_tests")
// Clean up before testing.
testutil.CleanServer(cfg.DataDir)
}
Expand Down
2 changes: 1 addition & 1 deletion server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewTestSingleConfig(c *assertutil.Checker) *config.Config {

cfg.AdvertiseClientUrls = cfg.ClientUrls
cfg.AdvertisePeerUrls = cfg.PeerUrls
cfg.DataDir, _ = os.MkdirTemp(os.TempDir(), "test_pd")
cfg.DataDir, _ = os.MkdirTemp("", "pd_tests")
cfg.InitialCluster = fmt.Sprintf("pd=%s", cfg.PeerUrls)
cfg.DisableStrictReconfigCheck = true
cfg.TickInterval = typeutil.NewDuration(100 * time.Millisecond)
Expand Down
2 changes: 1 addition & 1 deletion tests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type serverConfig struct {
}

func newServerConfig(name string, cc *clusterConfig, join bool) *serverConfig {
tempDir, _ := os.MkdirTemp(os.TempDir(), "pd-tests")
tempDir, _ := os.MkdirTemp("", "pd_tests")
return &serverConfig{
Name: name,
DataDir: tempDir,
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/global_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (suite *globalConfigTestSuite) TestEtcdNotStart() {
re.Error(err)

_, err = suite.server.LoadGlobalConfig(suite.server.Context(), &pdpb.LoadGlobalConfigRequest{
Names: []string{"test_etcd"},
Names: []string{"pd_tests"},
})
re.Error(err)
}
2 changes: 1 addition & 1 deletion tools/pd-backup/pdbackup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *backupTestSuite) TestGetBackupInfo() {
}
re.Equal(expected, actual)

tmpFile, err := os.CreateTemp(os.TempDir(), "pd_backup_info_test.json")
tmpFile, err := os.CreateTemp("", "pd_tests")
re.NoError(err)
defer os.RemoveAll(tmpFile.Name())

Expand Down
6 changes: 3 additions & 3 deletions tools/pd-ctl/tests/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (suite *configTestSuite) checkConfigForwardControl(cluster *pdTests.TestClu
leaderServer := cluster.GetLeaderServer()
pdAddr := leaderServer.GetAddr()

f, _ := os.CreateTemp(os.TempDir(), "pd_tests")
f, _ := os.CreateTemp("", "pd_tests")
fname := f.Name()
f.Close()
defer os.RemoveAll(fname)
Expand Down Expand Up @@ -571,7 +571,7 @@ func (suite *configTestSuite) checkPlacementRules(cluster *pdTests.TestCluster)
// test show
checkShowRuleKey(re, pdAddr, [][2]string{{placement.DefaultGroupID, placement.DefaultRuleID}})

f, _ := os.CreateTemp(os.TempDir(), "pd_tests")
f, _ := os.CreateTemp("", "pd_tests")
fname := f.Name()
f.Close()
defer os.RemoveAll(fname)
Expand Down Expand Up @@ -718,7 +718,7 @@ func (suite *configTestSuite) checkPlacementRuleBundle(cluster *pdTests.TestClus
re.NoError(json.Unmarshal(output, &bundle))
re.Equal(placement.GroupBundle{ID: placement.DefaultGroupID, Index: 0, Override: false, Rules: []*placement.Rule{{GroupID: placement.DefaultGroupID, ID: placement.DefaultRuleID, Role: placement.Voter, Count: 3}}}, bundle)

f, err := os.CreateTemp(os.TempDir(), "pd_tests")
f, err := os.CreateTemp("", "pd_tests")
re.NoError(err)
fname := f.Name()
f.Close()
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-simulator/simulator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewSimConfig(serverLogLevel string) *SimConfig {

cfg.AdvertiseClientUrls = cfg.ClientUrls
cfg.AdvertisePeerUrls = cfg.PeerUrls
cfg.DataDir, _ = os.MkdirTemp(os.TempDir(), "test_pd")
cfg.DataDir, _ = os.MkdirTemp("", "pd_tests")
cfg.InitialCluster = fmt.Sprintf("pd=%s", cfg.PeerUrls)
cfg.Log.Level = serverLogLevel
return &SimConfig{ServerConfig: cfg}
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-ut/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func main() {

if coverProfile != "" {
var err error
coverFileTempDir, err = os.MkdirTemp(os.TempDir(), "cov")
coverFileTempDir, err = os.MkdirTemp("", "cov")
if err != nil {
fmt.Println("create temp dir fail", coverFileTempDir)
os.Exit(1)
Expand Down Expand Up @@ -771,7 +771,7 @@ func buildTestBinaryMulti(pkgs []string) ([]byte, error) {
cmd.Args = append(cmd.Args, "-race")
}
cmd.Dir = workDir
outputFile, err := os.CreateTemp("", "test_pd_ut*.out")
outputFile, err := os.CreateTemp("", "pd_tests")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e9714b6

Please sign in to comment.