Fix testing etcd server not starting up if etcd is running on host.

This commit is contained in:
Joachim Bauch 2022-06-24 13:30:32 +02:00
parent af4bd51ec0
commit a761f135a8
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
1 changed files with 5 additions and 0 deletions

View File

@ -80,6 +80,11 @@ func NewEtcdForTest(t *testing.T) *embed.Etcd {
u.Host = net.JoinHostPort("localhost", strconv.Itoa(port))
cfg.LCUrls = []url.URL{*u}
cfg.ACUrls = []url.URL{*u}
peerListener := u
peerListener.Host = net.JoinHostPort("localhost", strconv.Itoa(port+1))
cfg.LPUrls = []url.URL{*peerListener}
cfg.APUrls = []url.URL{*peerListener}
cfg.InitialCluster = "default=" + peerListener.String()
etcd, err = embed.StartEtcd(cfg)
if isErrorAddressAlreadyInUse(err) {
continue