MCPcopy
hub / github.com/grafana/tempo / TestDrain_PruneTreeClearsOldBranches

Function TestDrain_PruneTreeClearsOldBranches

pkg/drain/drain_test.go:10–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestDrain_PruneTreeClearsOldBranches(t *testing.T) {
11 t.Parallel()
12
13 inputLines := []string{
14 "test test test 123",
15 "test test test 456",
16 "test test test 789",
17 "test test test 101",
18 "my name is 104",
19 "my name is 105",
20 "my name is 106",
21 "my name is 107",
22 }
23
24 drain := New("test-tenant", DefaultConfig())
25
26 for _, line := range inputLines {
27 drain.Train(line)
28 }
29
30 require.Len(t, drain.Clusters(), 2)
31 require.Equal(t, 16, countNodes(drain.rootNode))
32
33 // Delete a cluster manually
34 drain.idToCluster.Remove(1)
35 require.Len(t, drain.Clusters(), 1)
36 require.Equal(t, 16, countNodes(drain.rootNode), "expected same number of nodes before pruning")
37
38 drain.Prune()
39 require.Len(t, drain.Clusters(), 1)
40 require.Equal(t, 9, countNodes(drain.rootNode), "expected fewer nodes after pruning")
41}
42
43func countNodes(node *Node) int {
44 total := 1

Callers

nothing calls this directly

Calls 9

DefaultConfigFunction · 0.85
countNodesFunction · 0.85
TrainMethod · 0.80
ClustersMethod · 0.80
RemoveMethod · 0.80
NewFunction · 0.70
LenMethod · 0.65
PruneMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected