From 4ccfaf66eb7a5bba472eca1469a5681fa65e883a Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 30 Aug 2023 14:30:46 +0800 Subject: [PATCH] fix test Signed-off-by: lhy1024 --- pkg/storage/storage_tso_test.go | 14 ++++++++------ pkg/utils/etcdutil/testutil.go | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/storage/storage_tso_test.go b/pkg/storage/storage_tso_test.go index 1666abc4003..9718565d78f 100644 --- a/pkg/storage/storage_tso_test.go +++ b/pkg/storage/storage_tso_test.go @@ -27,7 +27,8 @@ import ( func TestSaveLoadTimestamp(t *testing.T) { re := require.New(t) - storage := newTestStorage(t) + storage, clean := newTestStorage(t) + defer clean() expectedTS := time.Now().Round(0) err := storage.SaveTimestamp(endpoint.TimestampKey, expectedTS) re.NoError(err) @@ -38,7 +39,8 @@ func TestSaveLoadTimestamp(t *testing.T) { func TestGlobalLocalTimestamp(t *testing.T) { re := require.New(t) - storage := newTestStorage(t) + storage, clean := newTestStorage(t) + defer clean() ltaKey := "lta" dc1LocationKey, dc2LocationKey := "dc1", "dc2" localTS1 := time.Now().Round(0) @@ -65,7 +67,8 @@ func TestGlobalLocalTimestamp(t *testing.T) { func TestTimestampTxn(t *testing.T) { re := require.New(t) - storage := newTestStorage(t) + storage, clean := newTestStorage(t) + defer clean() globalTS1 := time.Now().Round(0) err := storage.SaveTimestamp(endpoint.TimestampKey, globalTS1) re.NoError(err) @@ -79,9 +82,8 @@ func TestTimestampTxn(t *testing.T) { re.Equal(globalTS1, ts) } -func newTestStorage(t *testing.T) Storage { +func newTestStorage(t *testing.T) (Storage, func()) { _, client, clean := etcdutil.NewTestEtcdCluster(t, 1) - defer clean() rootPath := path.Join("/pd", strconv.FormatUint(100, 10)) - return NewStorageWithEtcdBackend(client, rootPath) + return NewStorageWithEtcdBackend(client, rootPath), clean } diff --git a/pkg/utils/etcdutil/testutil.go b/pkg/utils/etcdutil/testutil.go index 76db21e5c77..b2a1497f2be 100644 --- a/pkg/utils/etcdutil/testutil.go +++ b/pkg/utils/etcdutil/testutil.go @@ -117,6 +117,8 @@ func addEtcdMemberWithRetry(t *testing.T, cfg1 *embed.Config, client *clientv3.C if err != nil { re.Contains(err.Error(), "error validating peerURLs") if retry > 0 { + _, err := RemoveEtcdMember(client, addResp.Member.ID) + re.NoError(err) return addEtcdMemberWithRetry(t, cfg1, client, retry-1) } }