mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
integration: fix bind-addr-in-use
The bug happens when restarted member wants to listen on its original port, but finds out that it has been occupied by some client. Use well-known port instead of ephemeral port, so client cannot occupy the listen port anymore.
This commit is contained in:
parent
8e7fa9e201
commit
8e79fd85cb
@ -27,6 +27,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -49,6 +50,10 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
electionTicks = 10
|
electionTicks = 10
|
||||||
|
|
||||||
|
// integration test uses well-known ports to listen for each running member,
|
||||||
|
// which ensures restarted member could listen on specific port again.
|
||||||
|
nextListenPort int64 = 20000
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -596,7 +601,8 @@ func isMembersEqual(membs []client.Member, wmembs []client.Member) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newLocalListener(t *testing.T) net.Listener {
|
func newLocalListener(t *testing.T) net.Listener {
|
||||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
port := atomic.AddInt64(&nextListenPort, 1)
|
||||||
|
l, err := net.Listen("tcp", "127.0.0.1:"+strconv.FormatInt(port, 10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user