Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Mar 6, 2023
1 parent 8c89c58 commit 975a400
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"net"
"strconv"
"strings"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -248,10 +247,13 @@ func TestEtcdClientSync(t *testing.T) {
func TestEtcdWithHangLeaderEnableCheck(t *testing.T) {
re := require.New(t)
var err error
// Test with enable check.
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/utils/etcdutil/autoSyncInterval", "return(true)"))
err = checkEtcdWithHangLeader(t)
re.NoError(err)
require.NoError(t, failpoint.Disable("github.com/tikv/pd/pkg/utils/etcdutil/autoSyncInterval"))

// Test with disable check.
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/utils/etcdutil/closeKeepAliveCheck", "return(true)"))
err = checkEtcdWithHangLeader(t)
re.Error(err)
Expand Down Expand Up @@ -294,7 +296,7 @@ func checkEtcdWithHangLeader(t *testing.T) error {
func checkAddEtcdMember(t *testing.T, cfg1 *embed.Config, client *clientv3.Client) *embed.Etcd {
re := require.New(t)
cfg2 := NewTestSingleConfig(t)
cfg2.Name = "test_etcd_" + strconv.FormatInt(time.Now().UnixNano()%1000, 10)
cfg2.Name = genRandName()
cfg2.InitialCluster = cfg1.InitialCluster + fmt.Sprintf(",%s=%s", cfg2.Name, &cfg2.LPUrls[0])
cfg2.ClusterState = embed.ClusterStateFlagExisting
peerURL := cfg2.LPUrls[0].String()
Expand Down
6 changes: 5 additions & 1 deletion pkg/utils/etcdutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// NewTestSingleConfig is used to create a etcd config for the unit test purpose.
func NewTestSingleConfig(t *testing.T) *embed.Config {
cfg := embed.NewConfig()
cfg.Name = "test_etcd_" + strconv.FormatInt(time.Now().UnixNano()%1000, 10)
cfg.Name = genRandName()
cfg.Dir = t.TempDir()
cfg.WalDir = ""
cfg.Logger = "zap"
Expand All @@ -46,3 +46,7 @@ func NewTestSingleConfig(t *testing.T) *embed.Config {
cfg.ClusterState = embed.ClusterStateFlagNew
return cfg
}

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

0 comments on commit 975a400

Please sign in to comment.