Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Aug 30, 2023
1 parent 11f0a90 commit 4ccfaf6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/storage/storage_tso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions pkg/utils/etcdutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 4ccfaf6

Please sign in to comment.