Skip to content

Commit

Permalink
fix: TestMemberPromote should override PeerURLS
Browse files Browse the repository at this point in the history
Signed-off-by: Clement <[email protected]>
  • Loading branch information
clement2026 committed Aug 28, 2024
1 parent a0c0639 commit bb33591
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1693,5 +1693,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)

// 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 := testutils.ListenURL(&url)
if err != nil {
t.Fatal("failed to listen on %v: %v", url, err)
}
listeners = append(listeners, l)
}
m.PeerListeners = listeners

return m
}
14 changes: 14 additions & 0 deletions tests/framework/testutils/helpters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package testutils

import (
"errors"
"fmt"
"net"
"net/url"
"time"

clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -69,3 +72,14 @@ func MustClient(c intf.Client, err error) intf.Client {
}
return c
}

func ListenURL(addr *url.URL) (net.Listener, error) {
switch addr.Scheme {
case "http", "https":
return net.Listen("tcp", addr.Host)
case "unix", "unixs":
return net.Listen("unix", addr.Path)
default:
return nil, fmt.Errorf("unsupported scheme: %s", addr.Scheme)
}
}

0 comments on commit bb33591

Please sign in to comment.