mirror of https://github.com/hashicorp/consul
agent: Fixing port collision in tests
parent
6be29e17c2
commit
485f0a0c93
|
@ -2,15 +2,16 @@ package agent
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/consul/consul"
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
"github.com/hashicorp/consul/testutil"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/consul/consul"
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
"github.com/hashicorp/consul/testutil"
|
||||
)
|
||||
|
||||
var offset uint64
|
||||
|
@ -24,12 +25,12 @@ func nextConfig() *Config {
|
|||
conf.Datacenter = "dc1"
|
||||
conf.NodeName = fmt.Sprintf("Node %d", idx)
|
||||
conf.BindAddr = "127.0.0.1"
|
||||
conf.Ports.DNS = 18600 + idx
|
||||
conf.Ports.HTTP = 18500 + idx
|
||||
conf.Ports.RPC = 18400 + idx
|
||||
conf.Ports.DNS = 19000 + idx
|
||||
conf.Ports.HTTP = 18800 + idx
|
||||
conf.Ports.RPC = 18600 + idx
|
||||
conf.Ports.SerfLan = 18200 + idx
|
||||
conf.Ports.SerfWan = 18300 + idx
|
||||
conf.Ports.Server = 18100 + idx
|
||||
conf.Ports.SerfWan = 18400 + idx
|
||||
conf.Ports.Server = 18000 + idx
|
||||
conf.Server = true
|
||||
conf.ACLDatacenter = "dc1"
|
||||
conf.ACLMasterToken = "root"
|
||||
|
|
|
@ -81,9 +81,7 @@ func NewHTTPServers(agent *Agent, config *Config, logOutput io.Writer) ([]*HTTPS
|
|||
|
||||
// Start the server
|
||||
go http.Serve(list, mux)
|
||||
|
||||
servers := make([]*HTTPServer, 1)
|
||||
servers[0] = srv
|
||||
servers = append(servers, srv)
|
||||
}
|
||||
|
||||
if config.Ports.HTTP > 0 {
|
||||
|
@ -116,14 +114,7 @@ func NewHTTPServers(agent *Agent, config *Config, logOutput io.Writer) ([]*HTTPS
|
|||
|
||||
// Start the server
|
||||
go http.Serve(list, mux)
|
||||
|
||||
if servers != nil {
|
||||
// we already have the https server in servers, append
|
||||
servers = append(servers, srv)
|
||||
} else {
|
||||
servers := make([]*HTTPServer, 1)
|
||||
servers[0] = srv
|
||||
}
|
||||
servers = append(servers, srv)
|
||||
}
|
||||
|
||||
return servers, nil
|
||||
|
|
|
@ -25,16 +25,12 @@ func makeHTTPServer(t *testing.T) (string, *HTTPServer) {
|
|||
if err := os.Mkdir(uiDir, 755); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
conf.Addresses.HTTP = ""
|
||||
conf.Ports.HTTP = agent.config.Ports.HTTP
|
||||
conf.Ports.HTTPS = -1
|
||||
addr, _ := agent.config.ClientListener("", agent.config.Ports.HTTP)
|
||||
servers, err := NewHTTPServers(agent, conf, agent.logOutput)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if servers == nil || len(servers) == 0 {
|
||||
t.Fatalf(fmt.Sprintf("Could not create HTTP server to listen on: %s", addr.String()))
|
||||
if len(servers) == 0 {
|
||||
t.Fatalf(fmt.Sprintf("Failed to make HTTP server"))
|
||||
}
|
||||
return dir, servers[0]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue