mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
allocate unique port for each member in test cases
This commit is contained in:
parent
d849269dab
commit
24002fb099
@ -522,7 +522,7 @@ func isMembersEqual(membs []*pb.Member, wmembs []*pb.Member) bool {
|
||||
return cmp.Equal(membs, wmembs, cmpopts.IgnoreFields(pb.Member{}, "ID", "PeerURLs", "ClientURLs"))
|
||||
}
|
||||
|
||||
func newLocalListener(t testutil.TB) net.Listener {
|
||||
func NewLocalListener(t testutil.TB) net.Listener {
|
||||
c := atomic.AddInt32(&LocalListenCount, 1)
|
||||
// Go 1.8+ allows only numbers in port
|
||||
addr := fmt.Sprintf("127.0.0.1:%05d%05d", c+BasePort, os.Getpid())
|
||||
@ -620,7 +620,7 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member {
|
||||
peerScheme := SchemeFromTLSInfo(mcfg.PeerTLS)
|
||||
clientScheme := SchemeFromTLSInfo(mcfg.ClientTLS)
|
||||
|
||||
pln := newLocalListener(t)
|
||||
pln := NewLocalListener(t)
|
||||
m.PeerListeners = []net.Listener{pln}
|
||||
m.PeerURLs, err = types.NewURLs([]string{peerScheme + "://" + pln.Addr().String()})
|
||||
if err != nil {
|
||||
@ -628,7 +628,7 @@ func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member {
|
||||
}
|
||||
m.PeerTLSInfo = mcfg.PeerTLS
|
||||
|
||||
cln := newLocalListener(t)
|
||||
cln := NewLocalListener(t)
|
||||
m.ClientListeners = []net.Listener{cln}
|
||||
m.ClientURLs, err = types.NewURLs([]string{clientScheme + "://" + cln.Addr().String()})
|
||||
if err != nil {
|
||||
|
@ -54,7 +54,7 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) {
|
||||
}
|
||||
defer cli.Close()
|
||||
|
||||
urls := newEmbedURLs(2)
|
||||
urls := newEmbedURLs(t, 2)
|
||||
newCURLs, newPURLs := urls[:1], urls[1:]
|
||||
if _, err = cli.MemberAdd(context.Background(), []string{newPURLs[0].String()}); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -17,7 +17,6 @@ package snapshot_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -42,7 +41,7 @@ func TestSnapshotV3RestoreSingle(t *testing.T) {
|
||||
dbPath := createSnapshotFile(t, kvs)
|
||||
|
||||
clusterN := 1
|
||||
urls := newEmbedURLs(clusterN * 2)
|
||||
urls := newEmbedURLs(t, clusterN*2)
|
||||
cURLs, pURLs := urls[:clusterN], urls[clusterN:]
|
||||
|
||||
cfg := integration2.NewEmbedConfig(t, "s1")
|
||||
@ -172,7 +171,7 @@ func createSnapshotFile(t *testing.T, kvs []kv) string {
|
||||
testutil.SkipTestIfShortMode(t,
|
||||
"Snapshot creation tests are depending on embedded etcd server so are integration-level tests.")
|
||||
clusterN := 1
|
||||
urls := newEmbedURLs(clusterN * 2)
|
||||
urls := newEmbedURLs(t, clusterN*2)
|
||||
cURLs, pURLs := urls[:clusterN], urls[clusterN:]
|
||||
|
||||
cfg := integration2.NewEmbedConfig(t, "default")
|
||||
@ -223,7 +222,7 @@ func restoreCluster(t *testing.T, clusterN int, dbPath string) (
|
||||
cURLs []url.URL,
|
||||
pURLs []url.URL,
|
||||
srvs []*embed.Etcd) {
|
||||
urls := newEmbedURLs(clusterN * 2)
|
||||
urls := newEmbedURLs(t, clusterN*2)
|
||||
cURLs, pURLs = urls[:clusterN], urls[clusterN:]
|
||||
|
||||
ics := ""
|
||||
@ -284,11 +283,16 @@ func restoreCluster(t *testing.T, clusterN int, dbPath string) (
|
||||
}
|
||||
|
||||
// TODO: TLS
|
||||
func newEmbedURLs(n int) (urls []url.URL) {
|
||||
func newEmbedURLs(t testutil.TB, n int) (urls []url.URL) {
|
||||
urls = make([]url.URL, n)
|
||||
for i := 0; i < n; i++ {
|
||||
rand.Seed(int64(time.Now().Nanosecond()))
|
||||
u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d", rand.Intn(45000)))
|
||||
l := integration2.NewLocalListener(t)
|
||||
defer l.Close()
|
||||
|
||||
u, err := url.Parse(fmt.Sprintf("unix://%s", l.Addr()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
urls[i] = *u
|
||||
}
|
||||
return urls
|
||||
|
Loading…
x
Reference in New Issue
Block a user