diff --git a/memberlist_test.go b/memberlist_test.go index 75b3534a3..501af4e69 100644 --- a/memberlist_test.go +++ b/memberlist_test.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "testing" "time" @@ -23,18 +24,29 @@ import ( "github.com/stretchr/testify/require" ) -var bindLock sync.Mutex -var bindNum byte = 10 +var bindNum0 uint32 = 9 +var bindNum1 uint32 = 9 +var bindNum2 uint32 = 9 -func getBindAddrNet(network byte) net.IP { - bindLock.Lock() - defer bindLock.Unlock() +func getBindNum(bindNum *uint32, max uint32) uint32 { + atomic.AddUint32(bindNum, 1) + if *bindNum > max { + atomic.StoreUint32(bindNum, 10) + } + return *bindNum +} - result := net.IPv4(127, 0, network, bindNum) - bindNum++ - if bindNum > 255 { - bindNum = 10 +func getBindAddrNet(network byte) net.IP { + var bind uint32 + switch network { + case 0: + bind = getBindNum(&bindNum0, 255) + case 1: + bind = getBindNum(&bindNum1, 14) + case 2: + bind = getBindNum(&bindNum2, 14) } + result := net.IPv4(127, 0, network, byte(bind)) return result } @@ -1586,8 +1598,6 @@ func TestMemberlist_Join_IPv6(t *testing.T) { } // Since this binds to all interfaces we need to exclude other tests // from grabbing an interface. - bindLock.Lock() - defer bindLock.Unlock() c1 := DefaultLANConfig() c1.Name = "A" diff --git a/test/setup_subnet.sh b/test/setup_subnet.sh index b6397b207..d74626c55 100755 --- a/test/setup_subnet.sh +++ b/test/setup_subnet.sh @@ -29,10 +29,21 @@ case $OSTYPE in ;; esac -# Setup loopback -for j in 0 1 2 +# first loopback, use intensively +for ((i=10;i<256;i++)) + do + if [ "$action" = "up" ] + then + sudo ifconfig lo0 alias 127.0.0.$i up + else + sudo ifconfig lo0 127.0.0.$i delete + fi + done + +# Not use much, only need a few +for j in 1 2 do - for ((i=2;i<256;i++)) + for ((i=10;i<15;i++)) do if [ "$action" = "up" ] then @@ -42,3 +53,4 @@ do fi done done +