Reset nodes in frontend when scope-app restarted

When the scope-app restarts, it no longer has a
reference to the previous node set. Therefore,
the delta update adds *all* nodes but does not
remove legacy ones.

`reset==true` tells the frontend to start fresh.

Fixes #2708
This commit is contained in:
Roland Schilter
2017-07-13 14:19:11 +02:00
parent e603a28ca4
commit 5329efa528
4 changed files with 25 additions and 3 deletions

View File

@@ -10,11 +10,12 @@ type Diff struct {
Add []NodeSummary `json:"add"`
Update []NodeSummary `json:"update"`
Remove []string `json:"remove"`
Reset bool `json:"reset,omitempty"`
}
// TopoDiff gives you the diff to get from A to B.
func TopoDiff(a, b NodeSummaries) Diff {
diff := Diff{}
diff := Diff{Reset: a == nil}
notSeen := map[string]struct{}{}
for k := range a {

View File

@@ -79,6 +79,22 @@ func TestTopoDiff(t *testing.T) {
Update: []detailed.NodeSummary{nodeap},
},
},
{
label: "no previous nodes",
have: detailed.TopoDiff(nil, nodes(nodea)),
want: detailed.Diff{
Add: []detailed.NodeSummary{nodea},
Reset: true,
},
},
{
label: "empty previous nodes",
have: detailed.TopoDiff(nodes(), nodes(nodea)),
want: detailed.Diff{
Add: []detailed.NodeSummary{nodea},
Reset: false,
},
},
} {
sort.Strings(c.have.Remove)
sort.Sort(ByID(c.have.Add))