From 9b966ec1e60494294c108613ccbc93c9d3b03165 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 23 Mar 2016 15:36:46 -0700 Subject: [PATCH] Fixing the test --- client/consul/sync.go | 5 +++++ client/consul/sync_test.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/consul/sync.go b/client/consul/sync.go index b97e52b43..5b341cf84 100644 --- a/client/consul/sync.go +++ b/client/consul/sync.go @@ -334,3 +334,8 @@ func (c *ConsulService) filterConsulChecks(chks map[string]*consul.AgentCheck) m return nomadChecks } + +func (c *ConsulService) consulPresent() bool { + _, err := c.client.Agent().Self() + return err == nil +} diff --git a/client/consul/sync_test.go b/client/consul/sync_test.go index 77f8439ce..f566f9e32 100644 --- a/client/consul/sync_test.go +++ b/client/consul/sync_test.go @@ -16,6 +16,10 @@ func TestConsulServiceRegisterServices(t *testing.T) { if err != nil { t.Fatalf("Err: %v", err) } + // Skipping the test if consul isn't present + if !cs.consulPresent() { + return + } task := structs.Task{ Name: "foo", Services: []*structs.Service{ @@ -76,7 +80,7 @@ func TestConsulServiceRegisterServices(t *testing.T) { if _, ok := services["2"]; ok { t.Fatalf("Service with ID 2 should not be registered") } - if err := cs.Deregister(); err != nil { + if err := cs.Shutdown(); err != nil { t.Fatalf("err: %v", err) } time.Sleep(1 * time.Second)