Adds a before/after test for #3845.

This commit is contained in:
James Phillips 2018-02-05 16:18:29 -08:00
parent 5b245c0201
commit c718459e49
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
1 changed files with 58 additions and 0 deletions

View File

@ -547,6 +547,64 @@ func TestAgent_RemoveServiceRemovesAllChecks(t *testing.T) {
} }
} }
// TestAgent_ServiceWithTagChurn is designed to detect a class of issues where
// we would have unnecessary catalog churn for services with tags. See issues
// #3259, #3642, and #3845.
func TestAgent_ServiceWithTagChurn(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
svc := &structs.NodeService{
ID: "redis",
Service: "redis",
Port: 8000,
Tags: []string{"has", "tags"},
}
if err := a.AddService(svc, nil, true, ""); err != nil {
t.Fatalf("err: %v", err)
}
chk := &structs.HealthCheck{
CheckID: "redis-check",
ServiceID: "redis",
Status: api.HealthCritical,
}
chkt := &structs.CheckType{
TTL: time.Hour,
}
if err := a.AddCheck(chk, chkt, true, ""); err != nil {
t.Fatalf("err: %v", err)
}
if err := a.sync.State.SyncFull(); err != nil {
t.Fatalf("err: %v", err)
}
args := &structs.ServiceSpecificRequest{
Datacenter: "dc1",
ServiceName: "redis",
}
var before structs.IndexedHealthChecks
if err := a.RPC("Health.ServiceChecks", args, &before); err != nil {
t.Fatalf("err: %v", err)
}
if got, want := len(before.HealthChecks), 1; got != want {
t.Fatalf("got %d want %d", got, want)
}
for i := 0; i < 10; i++ {
if err := a.sync.State.SyncFull(); err != nil {
t.Fatalf("err: %v", err)
}
}
var after structs.IndexedHealthChecks
if err := a.RPC("Health.ServiceChecks", args, &after); err != nil {
t.Fatalf("err: %v", err)
}
verify.Values(t, "", after, before)
}
func TestAgent_AddCheck(t *testing.T) { func TestAgent_AddCheck(t *testing.T) {
t.Parallel() t.Parallel()
a := NewTestAgent(t.Name(), ` a := NewTestAgent(t.Name(), `