Skip to content

Commit 24ffaa5

Browse files
committed
fix: merging active controls on host
Need to do the special-case merge before `n.Latest.Merge()`, otherwise it picks just one set of controls. Also modified the test to call `Merge()` where the problem happened.
1 parent fc518cb commit 24ffaa5

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

report/node.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ func (n Node) Merge(other Node) Node {
218218
panic("Cannot merge nodes with different topology types: " + topology + " != " + other.Topology)
219219
}
220220

221+
// Special case to merge controls from two different probes.
222+
// Do this first, then the value we want will be picked as newest by n.Latest.Merge().
223+
if topology == Host {
224+
n = n.MergeActiveControls(other)
225+
}
226+
221227
newNode := Node{
222228
ID: id,
223229
Topology: topology,
@@ -229,11 +235,6 @@ func (n Node) Merge(other Node) Node {
229235
Children: n.Children.Merge(other.Children),
230236
}
231237

232-
// Special case to merge controls from two different probes.
233-
if topology == Host {
234-
newNode = newNode.MergeActiveControls(other)
235-
}
236-
237238
return newNode
238239
}
239240

report/node_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,24 @@ func TestCounters(t *testing.T) {
182182
}
183183
}
184184

185-
func TestActiveControls(t *testing.T) {
185+
func TestMergeActiveControls(t *testing.T) {
186186
mtime.NowForce(time.Now())
187187
defer mtime.NowReset()
188188

189189
controls1 := []string{"bar", "foo"}
190-
node1 := report.MakeNode("node1").WithLatestActiveControls(controls1...)
190+
node1 := report.MakeNode("node1").WithTopology(report.Host).WithLatestActiveControls(controls1...)
191191
assert.Equal(t, controls1, node1.ActiveControls())
192-
assert.Equal(t, controls1, sorted(node1.MergeActiveControls(node1).ActiveControls()))
192+
assert.Equal(t, controls1, sorted(node1.Merge(node1).ActiveControls()))
193193

194-
node2 := report.MakeNode("node2")
195-
assert.Equal(t, controls1, node1.MergeActiveControls(node2).ActiveControls())
196-
assert.Equal(t, controls1, node2.MergeActiveControls(node1).ActiveControls())
194+
node2 := report.MakeNode("node2") // has no active controls
195+
assert.Equal(t, controls1, node1.Merge(node2).ActiveControls())
196+
assert.Equal(t, controls1, node2.Merge(node1).ActiveControls())
197197

198198
controls2 := []string{"bar", "bor"}
199199
controls3 := []string{"bar", "bor", "foo"}
200200
node3 := report.MakeNode("node1").WithLatestActiveControls(controls2...)
201-
assert.Equal(t, controls3, sorted(node1.MergeActiveControls(node3).ActiveControls()))
202-
assert.Equal(t, controls3, sorted(node3.MergeActiveControls(node1).ActiveControls()))
201+
assert.Equal(t, controls3, sorted(node1.Merge(node3).ActiveControls()))
202+
assert.Equal(t, controls3, sorted(node3.Merge(node1).ActiveControls()))
203203
}
204204

205205
func sorted(s []string) []string {

0 commit comments

Comments
 (0)