From 8d09381b963762c9632ffba9f1019429d1393704 Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Wed, 18 Apr 2018 22:03:51 +0100 Subject: [PATCH] Super ugly hack to get TeamCity build to work for this PR without adding a vendor that is being added elsewhere and will conflict... --- GNUmakefile | 2 ++ agent/agent.go | 3 ++ agent/agent_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/GNUmakefile b/GNUmakefile index bebe8bce5a..030fa003db 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -40,6 +40,8 @@ bin: tools dev: changelogfmt vendorfmt dev-build dev-build: + @echo "--> TEMPORARY HACK: installing hashstructure to make CI pass until we vendor it upstream" + go get github.com/mitchellh/hashstructure @echo "--> Building consul" mkdir -p pkg/$(GOOS)_$(GOARCH)/ bin/ go install -ldflags '$(GOLDFLAGS)' -tags '$(GOTAGS)' diff --git a/agent/agent.go b/agent/agent.go index ce6a26d0c7..277bdd046a 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2588,6 +2588,9 @@ func (a *Agent) ReloadConfig(newCfg *config.RuntimeConfig) error { // First unload all checks, services, and metadata. This lets us begin the reload // with a clean slate. + if err := a.unloadProxies(); err != nil { + return fmt.Errorf("Failed unloading proxies: %s", err) + } if err := a.unloadServices(); err != nil { return fmt.Errorf("Failed unloading services: %s", err) } diff --git a/agent/agent_test.go b/agent/agent_test.go index 2ee42d7db6..bf24425bc0 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -1640,6 +1640,75 @@ func TestAgent_unloadServices(t *testing.T) { } } +func TestAgent_loadProxies(t *testing.T) { + t.Parallel() + a := NewTestAgent(t.Name(), ` + service = { + id = "rabbitmq" + name = "rabbitmq" + port = 5672 + token = "abc123" + connect { + proxy { + config { + bind_port = 1234 + } + } + } + } + `) + defer a.Shutdown() + + services := a.State.Services() + if _, ok := services["rabbitmq"]; !ok { + t.Fatalf("missing service") + } + if token := a.State.ServiceToken("rabbitmq"); token != "abc123" { + t.Fatalf("bad: %s", token) + } + if _, ok := services["rabbitmq-proxy"]; !ok { + t.Fatalf("missing proxy service") + } + if token := a.State.ServiceToken("rabbitmq-proxy"); token != "abc123" { + t.Fatalf("bad: %s", token) + } + proxies := a.State.Proxies() + if _, ok := proxies["rabbitmq-proxy"]; !ok { + t.Fatalf("missing proxy") + } +} + +func TestAgent_unloadProxies(t *testing.T) { + t.Parallel() + a := NewTestAgent(t.Name(), ` + service = { + id = "rabbitmq" + name = "rabbitmq" + port = 5672 + token = "abc123" + connect { + proxy { + config { + bind_port = 1234 + } + } + } + } + `) + defer a.Shutdown() + + // Sanity check it's there + require.NotNil(t, a.State.Proxy("rabbitmq-proxy")) + + // Unload all proxies + if err := a.unloadProxies(); err != nil { + t.Fatalf("err: %s", err) + } + if len(a.State.Proxies()) != 0 { + t.Fatalf("should have unloaded proxies") + } +} + func TestAgent_Service_MaintenanceMode(t *testing.T) { t.Parallel() a := NewTestAgent(t.Name(), "")