Removes bogus getPort() in favor of freeport.

This commit is contained in:
James Phillips 2017-11-08 19:52:36 -08:00
parent 72589c1de9
commit b94ba8aeb4
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
3 changed files with 6 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/lib/freeport"
"github.com/hashicorp/consul/testrpc"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/testutil/retry"
@ -24,10 +25,10 @@ func testClientConfig(t *testing.T) (string, *Config) {
config.NodeName = uniqueNodeName(t.Name())
config.RPCAddr = &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: getPort(),
Port: freeport.Get(1)[0],
}
config.SerfLANConfig.MemberlistConfig.BindAddr = "127.0.0.1"
config.SerfLANConfig.MemberlistConfig.BindPort = getPort()
config.SerfLANConfig.MemberlistConfig.BindPort = freeport.Get(1)[0]
config.SerfLANConfig.MemberlistConfig.ProbeTimeout = 200 * time.Millisecond
config.SerfLANConfig.MemberlistConfig.ProbeInterval = time.Second
config.SerfLANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond

View File

@ -9,6 +9,7 @@ import (
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/lib/freeport"
"github.com/hashicorp/consul/testrpc"
"github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/raft"
@ -146,7 +147,7 @@ func TestOperator_RaftRemovePeerByAddress(t *testing.T) {
// Try to remove a peer that's not there.
arg := structs.RaftRemovePeerRequest{
Datacenter: "dc1",
Address: raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", getPort())),
Address: raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.Get(1)[0])),
}
var reply struct{}
err := msgpackrpc.CallWithCodec(codec, "Operator.RaftRemovePeerByAddress", &arg, &reply)
@ -274,7 +275,7 @@ func TestOperator_RaftRemovePeerByID(t *testing.T) {
// Add it manually to Raft.
{
future := s1.raft.AddVoter(arg.ID, raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", getPort())), 0, 0)
future := s1.raft.AddVoter(arg.ID, raft.ServerAddress(fmt.Sprintf("127.0.0.1:%d", freeport.Get(1)[0])), 0, 0)
if err := future.Error(); err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -3,7 +3,6 @@ package consul
import (
"fmt"
"log"
"math/rand"
"net"
"os"
"strings"
@ -21,10 +20,6 @@ import (
"github.com/hashicorp/go-uuid"
)
func getPort() int {
return 1030 + int(rand.Int31n(64400))
}
func configureTLS(config *Config) {
config.CAFile = "../../test/ca/root.cer"
config.CertFile = "../../test/key/ourdomain.cer"