From f6b7dcbcf6196ce73a0db35cff2e81183f573656 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 8 Nov 2017 19:52:36 -0800 Subject: [PATCH] Removes bogus getPort() in favor of freeport. --- agent/consul/client_test.go | 5 +++-- agent/consul/operator_raft_endpoint_test.go | 5 +++-- agent/consul/server_test.go | 5 ----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/agent/consul/client_test.go b/agent/consul/client_test.go index 1958ba9fb0..20647b3f66 100644 --- a/agent/consul/client_test.go +++ b/agent/consul/client_test.go @@ -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 diff --git a/agent/consul/operator_raft_endpoint_test.go b/agent/consul/operator_raft_endpoint_test.go index 9bb84bc09c..8c73cd522c 100644 --- a/agent/consul/operator_raft_endpoint_test.go +++ b/agent/consul/operator_raft_endpoint_test.go @@ -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) } diff --git a/agent/consul/server_test.go b/agent/consul/server_test.go index a4853863a0..d65e2c7d7c 100644 --- a/agent/consul/server_test.go +++ b/agent/consul/server_test.go @@ -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"