From 651e42e54ec89375c6ed9bd17ab4c3815f197aeb Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 23 Dec 2017 22:21:24 +0000 Subject: [PATCH] fix accidental report fixture modification Report.Copy() shallow-copies the nodes in Report.Nodes. Hence Node.Metrics is shared between the original and the copy. Hence bad things happen when modifying it. This bug has laid dormant because by luck other tests in detailed_test involving metrics are executed first. --- render/detailed/summary_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/render/detailed/summary_test.go b/render/detailed/summary_test.go index 9d142b4a2..fcc375586 100644 --- a/render/detailed/summary_test.go +++ b/render/detailed/summary_test.go @@ -49,8 +49,10 @@ func TestSummaries(t *testing.T) { t1, t2 := mtime.Now().Add(-1*time.Minute), mtime.Now() metric := report.MakeMetric([]report.Sample{{Timestamp: t1, Value: 1}, {Timestamp: t2, Value: 2}}) input := fixture.Report.Copy() - - input.Process.Nodes[fixture.ClientProcess1NodeID].Metrics[process.CPUUsage] = metric + processNode := input.Process.Nodes[fixture.ClientProcess1NodeID] + processNode.Metrics = processNode.Metrics.Copy() + processNode.Metrics[process.CPUUsage] = metric + input.Process.Nodes[fixture.ClientProcess1NodeID] = processNode have := detailed.Summaries(report.RenderContext{Report: input}, render.ProcessRenderer.Render(input).Nodes) node, ok := have[fixture.ClientProcess1NodeID]