Skip to content

Commit

Permalink
Merge pull request #19136 from ahrtr/member_promote_test_20250107
Browse files Browse the repository at this point in the history
Fix the inconsistent between listen peerURL and advertise peerURL
  • Loading branch information
ahrtr authored Jan 7, 2025
2 parents fce823a + e78cec8 commit aac7ef6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 6 additions & 8 deletions tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (c *Cluster) ProtoMembers() []*pb.Member {
return ms
}

func (c *Cluster) mustNewMember(t testutil.TB) *Member {
func (c *Cluster) MustNewMember(t testutil.TB) *Member {
memberNumber := c.LastMemberNum
c.LastMemberNum++

Expand Down Expand Up @@ -299,7 +299,7 @@ func (c *Cluster) mustNewMember(t testutil.TB) *Member {

// addMember return PeerURLs of the added member.
func (c *Cluster) addMember(t testutil.TB) types.URLs {
m := c.mustNewMember(t)
m := c.MustNewMember(t)

scheme := SchemeFromTLSInfo(c.Cfg.PeerTLS)

Expand Down Expand Up @@ -1394,7 +1394,7 @@ func NewCluster(t testutil.TB, cfg *ClusterConfig) *Cluster {
c := &Cluster{Cfg: cfg}
ms := make([]*Member, cfg.Size)
for i := 0; i < cfg.Size; i++ {
ms[i] = c.mustNewMember(t)
ms[i] = c.MustNewMember(t)
}
c.Members = ms
if err := c.fillClusterForMembers(); err != nil {
Expand Down Expand Up @@ -1580,7 +1580,7 @@ func (c *Cluster) GetLearnerMembers() ([]*pb.Member, error) {
// AddAndLaunchLearnerMember creates a learner member, adds it to Cluster
// via v3 MemberAdd API, and then launches the new member.
func (c *Cluster) AddAndLaunchLearnerMember(t testutil.TB) {
m := c.mustNewMember(t)
m := c.MustNewMember(t)
m.IsLearner = true

scheme := SchemeFromTLSInfo(c.Cfg.PeerTLS)
Expand Down Expand Up @@ -1679,9 +1679,8 @@ func (p SortableProtoMemberSliceByPeerURLs) Less(i, j int) bool {
}
func (p SortableProtoMemberSliceByPeerURLs) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

// MustNewMember creates a new member instance based on the response of V3 Member Add API.
func (c *Cluster) MustNewMember(t testutil.TB, resp *clientv3.MemberAddResponse) *Member {
m := c.mustNewMember(t)
// InitializeMemberWithResponse initializes a member with the response
func (c *Cluster) InitializeMemberWithResponse(t testutil.TB, m *Member, resp *clientv3.MemberAddResponse) {
m.IsLearner = resp.Member.IsLearner
m.NewCluster = false

Expand All @@ -1691,5 +1690,4 @@ func (c *Cluster) MustNewMember(t testutil.TB, resp *clientv3.MemberAddResponse)
}
m.InitialPeerURLsMap[m.Name] = types.MustNewURLs(resp.Member.PeerURLs)
c.Members = append(c.Members, m)
return m
}
7 changes: 4 additions & 3 deletions tests/integration/clientv3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ func TestMemberPromote(t *testing.T) {
followerIdx := (leaderIdx + 1) % 3
capi := clus.Client(followerIdx)

urls := []string{"http://127.0.0.1:1234"}
learnerMember := clus.MustNewMember(t)
urls := learnerMember.PeerURLs.StringSlice()
memberAddResp, err := capi.MemberAddAsLearner(context.Background(), urls)
if err != nil {
t.Fatalf("failed to add member %v", err)
Expand Down Expand Up @@ -262,9 +263,9 @@ func TestMemberPromote(t *testing.T) {
t.Fatalf("expecting error to contain %s, got %s", expectedErrKeywords, err.Error())
}

// create and launch learner member based on the response of V3 Member Add API.
// Initialize and launch learner member based on the response of V3 Member Add API.
// (the response has information on peer urls of the existing members in cluster)
learnerMember := clus.MustNewMember(t, memberAddResp)
clus.InitializeMemberWithResponse(t, learnerMember, memberAddResp)

if err = learnerMember.Launch(); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit aac7ef6

Please sign in to comment.