Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce number of addresses in loopback #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions memberlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand All @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 15 additions & 3 deletions test/setup_subnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,3 +53,4 @@ do
fi
done
done