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

Function TestCombine

pkg/model/combine_test.go:14–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCombine(t *testing.T) {
15 t1 := test.MakeTrace(10, []byte{0x01, 0x02})
16 t2 := test.MakeTrace(10, []byte{0x01, 0x03})
17
18 trace.SortTrace(t1)
19 trace.SortTrace(t2)
20
21 // split t2 into two traces
22 t2a := &tempopb.Trace{}
23 t2b := &tempopb.Trace{}
24 t2c := &tempopb.Trace{}
25 for _, b := range t2.ResourceSpans {
26 switch rand.Int() % 3 {
27 case 0:
28 t2a.ResourceSpans = append(t2a.ResourceSpans, b)
29 case 1:
30 t2b.ResourceSpans = append(t2b.ResourceSpans, b)
31 case 2:
32 t2c.ResourceSpans = append(t2c.ResourceSpans, b)
33 }
34 }
35
36 tests := []struct {
37 name string
38 traces [][]byte
39 expected *tempopb.Trace
40 expectError bool
41 expectCombined bool
42 }{
43 {
44 name: "no traces",
45 expectError: true,
46 },
47 {
48 name: "same trace",
49 traces: [][]byte{mustMarshalToObject(t1, CurrentEncoding), mustMarshalToObject(t1, CurrentEncoding)},
50 expected: t1,
51 },
52 {
53 name: "3 traces",
54 traces: [][]byte{mustMarshalToObject(t2a, CurrentEncoding), mustMarshalToObject(t2b, CurrentEncoding), mustMarshalToObject(t2c, CurrentEncoding)},
55 expected: t2,
56 expectCombined: true,
57 },
58 {
59 name: "1 trace",
60 traces: [][]byte{mustMarshalToObject(t1, CurrentEncoding)},
61 expected: t1,
62 },
63 {
64 name: "nil trace",
65 traces: [][]byte{mustMarshalToObject(t1, CurrentEncoding), nil},
66 expected: t1,
67 expectCombined: true,
68 },
69 {
70 name: "nil trace 2",
71 traces: [][]byte{nil, mustMarshalToObject(t1, CurrentEncoding)},

Callers

nothing calls this directly

Calls 8

MakeTraceFunction · 0.92
SortTraceFunction · 0.92
mustMarshalToObjectFunction · 0.85
IntMethod · 0.80
CombineMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected