Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix MustNewMember #18584

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,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 {
// Pass nil for tlsinfo if the member's PeerURLs don't use HTTPS.
func (c *Cluster) MustNewMember(t testutil.TB, resp *clientv3.MemberAddResponse, tlsinfo *transport.TLSInfo) *Member {
m := c.mustNewMember(t)
m.IsLearner = resp.Member.IsLearner
m.NewCluster = false
Expand All @@ -1693,5 +1694,20 @@ 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)

// c.mustNewMember(t) creates a new member without using resp.Member.PeerURLs.
// We should override PeerURLs and PeerListeners set by mustNewMember.
urls := types.MustNewURLs(resp.Member.PeerURLs)
m.PeerURLs = urls
var listeners []net.Listener
for _, url := range urls {
l, err := transport.NewListener(url.Host, url.Scheme, tlsinfo)
if err != nil {
t.Fatal("failed to listen on %v: %v", url, err)
}
listeners = append(listeners, l)
}
m.PeerListeners = listeners

return m
}
2 changes: 1 addition & 1 deletion tests/integration/clientv3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestMemberPromote(t *testing.T) {

// create 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)
learnerMember := clus.MustNewMember(t, memberAddResp, nil)

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