Speeding up health change detection by separating it from catalog services check.
This commit is contained in:
parent
9cb07d026f
commit
db1baf80a9
2 changed files with 240 additions and 23 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
"text/template"
|
||||
|
||||
"github.com/BurntSushi/ty/fun"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
@ -606,3 +607,146 @@ func TestConsulCatalogNodeSorter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConsulCatalogGetChangedKeys(t *testing.T) {
|
||||
type Input struct {
|
||||
currState map[string][]string
|
||||
prevState map[string][]string
|
||||
}
|
||||
|
||||
type Output struct {
|
||||
addedKeys []string
|
||||
removedKeys []string
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
input Input
|
||||
output Output
|
||||
}{
|
||||
{
|
||||
input: Input{
|
||||
currState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"bar-service": {"v1"},
|
||||
"baz-service": {"v1"},
|
||||
"qux-service": {"v1"},
|
||||
"quux-service": {"v1"},
|
||||
"quuz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"grault-service": {"v1"},
|
||||
"garply-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
prevState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"bar-service": {"v1"},
|
||||
"baz-service": {"v1"},
|
||||
"qux-service": {"v1"},
|
||||
"quux-service": {"v1"},
|
||||
"quuz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"grault-service": {"v1"},
|
||||
"garply-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
},
|
||||
output: Output{
|
||||
addedKeys: []string{},
|
||||
removedKeys: []string{},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: Input{
|
||||
currState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"bar-service": {"v1"},
|
||||
"baz-service": {"v1"},
|
||||
"qux-service": {"v1"},
|
||||
"quux-service": {"v1"},
|
||||
"quuz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"grault-service": {"v1"},
|
||||
"garply-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
prevState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"bar-service": {"v1"},
|
||||
"baz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"grault-service": {"v1"},
|
||||
"garply-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
},
|
||||
output: Output{
|
||||
addedKeys: []string{"qux-service", "quux-service", "quuz-service"},
|
||||
removedKeys: []string{},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: Input{
|
||||
currState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"qux-service": {"v1"},
|
||||
"quux-service": {"v1"},
|
||||
"quuz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"grault-service": {"v1"},
|
||||
"garply-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
prevState: map[string][]string{
|
||||
"foo-service": {"v1"},
|
||||
"bar-service": {"v1"},
|
||||
"baz-service": {"v1"},
|
||||
"qux-service": {"v1"},
|
||||
"quux-service": {"v1"},
|
||||
"quuz-service": {"v1"},
|
||||
"corge-service": {"v1"},
|
||||
"waldo-service": {"v1"},
|
||||
"fred-service": {"v1"},
|
||||
"plugh-service": {"v1"},
|
||||
"xyzzy-service": {"v1"},
|
||||
"thud-service": {"v1"},
|
||||
},
|
||||
},
|
||||
output: Output{
|
||||
addedKeys: []string{"grault-service", "garply-service"},
|
||||
removedKeys: []string{"bar-service", "baz-service"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
addedKeys, removedKeys := getChangedKeys(c.input.currState, c.input.prevState)
|
||||
|
||||
if !reflect.DeepEqual(fun.Set(addedKeys), fun.Set(c.output.addedKeys)) {
|
||||
t.Fatalf("Added keys comparison results: got %q, want %q", addedKeys, c.output.addedKeys)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(fun.Set(removedKeys), fun.Set(c.output.removedKeys)) {
|
||||
t.Fatalf("Removed keys comparison results: got %q, want %q", removedKeys, c.output.removedKeys)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue