From e78cec8e528923e299fa98e8cebc8f9f16852d46 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Tue, 7 Jan 2025 12:30:46 +0000 Subject: [PATCH] Fix the inconsistent between listen peerURL and advertise peerURL Signed-off-by: Benjamin Wang --- tests/framework/integration/cluster.go | 14 ++++++-------- tests/integration/clientv3/cluster_test.go | 7 ++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index f78af573f34..229611fe2fa 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -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++ @@ -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) @@ -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 { @@ -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) @@ -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 @@ -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 } diff --git a/tests/integration/clientv3/cluster_test.go b/tests/integration/clientv3/cluster_test.go index 9ed510108b8..7de4d0ff8bc 100644 --- a/tests/integration/clientv3/cluster_test.go +++ b/tests/integration/clientv3/cluster_test.go @@ -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) @@ -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)