Skip to content

Commit

Permalink
Merge pull request #918 from hashicorp/h-checkfix
Browse files Browse the repository at this point in the history
Deregister all associated checks on service deregistration
  • Loading branch information
armon committed May 7, 2015
2 parents 7062ecc + 3ed0146 commit e59ef3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"

"github.com/hashicorp/consul/consul"
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e59ef3a

Please sign in to comment.