etcd: Use dedicated port for HTTP listener when testing to silent warning.

Follow-up to #475
This commit is contained in:
Joachim Bauch 2023-06-12 12:06:43 +02:00
parent b0f677dbc4
commit c11902b2f3
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 7 additions and 1 deletions

View file

@ -81,8 +81,11 @@ func NewEtcdForTest(t *testing.T) *embed.Etcd {
u.Host = net.JoinHostPort("localhost", strconv.Itoa(port))
cfg.ListenClientUrls = []url.URL{*u}
cfg.AdvertiseClientUrls = []url.URL{*u}
httpListener := u
httpListener.Host = net.JoinHostPort("localhost", strconv.Itoa(port+1))
cfg.ListenClientHttpUrls = []url.URL{*httpListener}
peerListener := u
peerListener.Host = net.JoinHostPort("localhost", strconv.Itoa(port+1))
peerListener.Host = net.JoinHostPort("localhost", strconv.Itoa(port+2))
cfg.ListenPeerUrls = []url.URL{*peerListener}
cfg.AdvertisePeerUrls = []url.URL{*peerListener}
cfg.InitialCluster = "default=" + peerListener.String()

View file

@ -80,6 +80,9 @@ func newEtcdForTesting(t *testing.T) *embed.Etcd {
for port := 50000; port < 50100; port++ {
u.Host = net.JoinHostPort("localhost", strconv.Itoa(port))
cfg.ListenClientUrls = []url.URL{*u}
httpListener := u
httpListener.Host = net.JoinHostPort("localhost", strconv.Itoa(port+1))
cfg.ListenClientHttpUrls = []url.URL{*httpListener}
etcd, err = embed.StartEtcd(cfg)
if isErrorAddressAlreadyInUse(err) {
continue