From 84f480528a1e6f498567570cd6087042cfeda781 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 16 Oct 2017 16:58:41 -0700 Subject: [PATCH] Consul test server fork without porter/rpc.ports --- GNUmakefile | 3 +- .../hashicorp/consul/testutil/server.go | 43 +++++++++++++------ .../consul/testutil/server_methods.go | 4 +- vendor/vendor.json | 10 ++--- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 16ac9d185..900ea4401 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -150,7 +150,8 @@ deps: ## Install build and development dependencies go get -u github.com/elazarl/go-bindata-assetfs/... go get -u github.com/hashicorp/vault go get -u github.com/a8m/tree/cmd/tree - go get -u github.com/hashicorp/consul/test/porter/cmd/porter + ## Unneeded since we use Consul's no-porter branch + ##go get -u github.com/hashicorp/consul/test/porter/cmd/porter .PHONY: check check: ## Lint the source code diff --git a/vendor/github.com/hashicorp/consul/testutil/server.go b/vendor/github.com/hashicorp/consul/testutil/server.go index c01471271..22880a869 100644 --- a/vendor/github.com/hashicorp/consul/testutil/server.go +++ b/vendor/github.com/hashicorp/consul/testutil/server.go @@ -27,7 +27,6 @@ import ( "testing" "time" - "github.com/hashicorp/consul/test/porter" "github.com/hashicorp/consul/testutil/retry" "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-uuid" @@ -48,6 +47,9 @@ type TestPortConfig struct { SerfLan int `json:"serf_lan,omitempty"` SerfWan int `json:"serf_wan,omitempty"` Server int `json:"server,omitempty"` + + // Deprecated + RPC int `json:"rpc,omitempty"` } // TestAddressConfig contains the bind addresses for various @@ -111,12 +113,8 @@ func defaultServerConfig() *TestServerConfig { panic(err) } - ports, err := porter.RandomPorts(6) - if err != nil { - panic(err) - } return &TestServerConfig{ - NodeName: "node-" + nodeID, + NodeName: fmt.Sprintf("node%d", randomPort()), NodeID: nodeID, DisableCheckpoint: true, Performance: &TestPerformanceConfig{ @@ -128,17 +126,28 @@ func defaultServerConfig() *TestServerConfig { Bind: "127.0.0.1", Addresses: &TestAddressConfig{}, Ports: &TestPortConfig{ - DNS: ports[0], - HTTP: ports[1], - HTTPS: ports[2], - SerfLan: ports[3], - SerfWan: ports[4], - Server: ports[5], + DNS: randomPort(), + HTTP: randomPort(), + HTTPS: randomPort(), + SerfLan: randomPort(), + SerfWan: randomPort(), + Server: randomPort(), + //RPC: randomPort(), }, ReadyTimeout: 10 * time.Second, } } +// randomPort asks the kernel for a random port to use. +func randomPort() int { + l, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + panic(err) + } + defer l.Close() + return l.Addr().(*net.TCPAddr).Port +} + // TestService is used to serialize a service definition. type TestService struct { ID string `json:",omitempty"` @@ -191,7 +200,15 @@ func NewTestServerConfig(cb ServerConfigCallback) (*TestServer, error) { // configuring or starting the server, the server will NOT be running when the // function returns (thus you do not need to stop it). func NewTestServerConfigT(t *testing.T, cb ServerConfigCallback) (*TestServer, error) { - return newTestServerConfigT(t, cb) + var server *TestServer + retry.Run(t, func(r *retry.R) { + var err error + server, err = newTestServerConfigT(t, cb) + if err != nil { + r.Fatalf("failed starting test server: %v", err) + } + }) + return server, nil } // newTestServerConfigT is the internal helper for NewTestServerConfigT. diff --git a/vendor/github.com/hashicorp/consul/testutil/server_methods.go b/vendor/github.com/hashicorp/consul/testutil/server_methods.go index dec512054..8f4b067ad 100644 --- a/vendor/github.com/hashicorp/consul/testutil/server_methods.go +++ b/vendor/github.com/hashicorp/consul/testutil/server_methods.go @@ -25,13 +25,13 @@ const ( // JoinLAN is used to join local datacenters together. func (s *TestServer) JoinLAN(t *testing.T, addr string) { - resp := s.put(t, "/v1/agent/join/"+addr, nil) + resp := s.get(t, "/v1/agent/join/"+addr) defer resp.Body.Close() } // JoinWAN is used to join remote datacenters together. func (s *TestServer) JoinWAN(t *testing.T, addr string) { - resp := s.put(t, "/v1/agent/join/"+addr+"?wan=1", nil) + resp := s.get(t, "/v1/agent/join/"+addr+"?wan=1") resp.Body.Close() } diff --git a/vendor/vendor.json b/vendor/vendor.json index 800e15914..21fc9fdf7 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -767,16 +767,16 @@ "revisionTime": "2017-10-16T16:22:40Z" }, { - "checksumSHA1": "srD5fzGnxoAqvR6oIE4JBJ1OuT8=", + "checksumSHA1": "AZh3opzONxPrOi+4Io2+OomdKgM=", "path": "github.com/hashicorp/consul/testutil", - "revision": "51ea240df8476e02215d53fbfad5838bf0d44d21", - "revisionTime": "2017-10-16T16:22:40Z" + "revision": "745fd38728f28061c9f5bfe323d68ee25f2cd07b", + "revisionTime": "2017-10-16T23:19:35Z" }, { "checksumSHA1": "J8TTDc84MvAyXE/FrfgS+xc/b6s=", "path": "github.com/hashicorp/consul/testutil/retry", - "revision": "51ea240df8476e02215d53fbfad5838bf0d44d21", - "revisionTime": "2017-10-16T16:22:40Z" + "revision": "745fd38728f28061c9f5bfe323d68ee25f2cd07b", + "revisionTime": "2017-10-16T23:19:35Z" }, { "path": "github.com/hashicorp/errwrap",