Skip to content

Commit

Permalink
client/test: add some tests where member change (#7972)
Browse files Browse the repository at this point in the history
ref #4399

Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 authored Mar 26, 2024
1 parent 29a4a2a commit 13188c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func TestUpdateURLs(t *testing.T) {
re.Equal(getURLs([]*pdpb.Member{members[1], members[3], members[2]}), cli.GetServiceURLs())
cli.updateURLs(members)
re.Equal(getURLs([]*pdpb.Member{members[1], members[3], members[2], members[0]}), cli.GetServiceURLs())
cli.updateURLs(members[1:])
re.Equal(getURLs([]*pdpb.Member{members[1], members[3], members[2]}), cli.GetServiceURLs())
cli.updateURLs(members[2:])
re.Equal(getURLs([]*pdpb.Member{members[3], members[2]}), cli.GetServiceURLs())
cli.updateURLs(members[3:])
re.Equal(getURLs([]*pdpb.Member{members[3]}), cli.GetServiceURLs())
}

const testClientURL = "tmp://test.url:5255"
Expand Down
26 changes: 24 additions & 2 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ func TestClientLeaderChange(t *testing.T) {
re.Equal(endpoints, urls)
}

func TestLeaderTransfer(t *testing.T) {
func TestLeaderTransferAndMoveCluster(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 2)
cluster, err := tests.NewTestCluster(ctx, 3)
re.NoError(err)
defer cluster.Destroy()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/member/skipCampaignLeaderCheck", "return(true)"))
Expand Down Expand Up @@ -222,6 +222,28 @@ func TestLeaderTransfer(t *testing.T) {
newLeaderName := cluster.WaitLeader()
re.NotEqual(oldLeaderName, newLeaderName)
}

// ABC->ABCDEF
oldServers := cluster.GetServers()
oldLeaderName := cluster.WaitLeader()
for i := 0; i < 3; i++ {
newPD, err := cluster.Join(ctx)
re.NoError(err)
re.NoError(newPD.Run())
oldLeaderName = cluster.WaitLeader()
time.Sleep(5 * time.Second)
}

// ABCDEF->DEF
oldNames := make([]string, 0)
for _, s := range oldServers {
oldNames = append(oldNames, s.GetServer().GetMemberInfo().GetName())
s.Stop()
}
newLeaderName := cluster.WaitLeader()
re.NotEqual(oldLeaderName, newLeaderName)
re.NotContains(oldNames, newLeaderName)

close(quit)
wg.Wait()
}
Expand Down

0 comments on commit 13188c9

Please sign in to comment.