Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Nov 25, 2015
1 parent 92c635d commit e9019d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (c *ConsulService) performSync(agent *consul.Agent) {
// Remove the tracked services which tasks no longer references
for serviceId, ts := range c.trackedServices {
if !ts.IsServiceValid() {
c.logger.Printf("[INFO] consul: Removing service: %s since the task doesn't have it anymore", ts.service.Name)
c.logger.Printf("[DEBUG] consul: Removing service: %s since the task doesn't have it anymore", ts.service.Name)
c.deregisterService(serviceId)
}
}
Expand Down
21 changes: 6 additions & 15 deletions client/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,28 @@ func TestConsul_Services_Deleted_From_Task(t *testing.T) {
},
}
c.Register(&task, "1")
if len(c.trackedServices) != 1 {
t.Fatalf("Expected tracked services: %v, Actual: %v", 1, len(c.trackedServices))
}
task.Services = []*structs.Service{}

c.performSync(c.client.Agent())
if len(c.trackedServices) != 0 {
t.Fatal("All services should have been de-registered")
t.Fatalf("Expected tracked services: %v, Actual: %v", 0, len(c.trackedServices))
}
}

func TestConsul_Service_Should_Be_Re_Reregistered_On_Change(t *testing.T) {
c := newConsulService()
var services []*structs.Service
task := structs.Task{
Name: "redis",
Services: services,
Resources: &structs.Resources{
Networks: []*structs.NetworkResource{
{
IP: "10.10.0.1",
DynamicPorts: []structs.Port{{"db", 20413}},
},
},
},
}
task := newTask()
s1 := structs.Service{
Id: "1-example-cache-redis",
Name: "example-cache-redis",
Tags: []string{"global"},
PortLabel: "db",
}
task.Services = append(task.Services, &s1)
c.Register(&task, "1")
c.Register(task, "1")

s1.Tags = []string{"frontcache"}

Expand Down

0 comments on commit e9019d1

Please sign in to comment.