agent: use service ID field to determine associated health checks during deregister

This commit is contained in:
Ryan Uber 2015-05-07 15:30:01 -07:00
parent e7b00723f4
commit d0a28482ff
2 changed files with 17 additions and 4 deletions

View File

@ -10,7 +10,6 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"github.com/hashicorp/consul/consul"
@ -703,9 +702,8 @@ func (a *Agent) RemoveService(serviceID string, persist bool) error {
}
// Deregister any associated health checks
for checkID, _ := range a.state.Checks() {
prefix := "service:" + serviceID
if checkID != prefix && !strings.HasPrefix(checkID, prefix+":") {
for checkID, health := range a.state.Checks() {
if health.ServiceID != serviceID {
continue
}
if err := a.RemoveCheck(checkID, persist); err != nil {

View File

@ -265,12 +265,27 @@ func TestAgent_RemoveService(t *testing.T) {
t.Fatalf("err: %v", err)
}
// Add a check after the fact with a specific check ID
check := &CheckDefinition{
ID: "check2",
Name: "check2",
ServiceID: "memcache",
CheckType: CheckType{TTL: time.Minute},
}
hc := check.HealthCheck("node1")
if err := agent.AddCheck(hc, &check.CheckType, false, ""); err != nil {
t.Fatalf("err: %s", err)
}
if err := agent.RemoveService("memcache", false); err != nil {
t.Fatalf("err: %s", err)
}
if _, ok := agent.state.Checks()["service:memcache"]; ok {
t.Fatalf("have memcache check")
}
if _, ok := agent.state.Checks()["check2"]; ok {
t.Fatalf("have check2 check")
}
}
// Removing a service with multiple checks works