MCPcopy
hub / github.com/cubefs/cubefs / TestExplicitReferences

Function TestExplicitReferences

blobstore/common/trace/tracer_test.go:81–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func TestExplicitReferences(t *testing.T) {
82 tracer := NewTracer("blobstore")
83 defer tracer.Close()
84
85 parentSpan := tracer.StartSpan("parent").(*spanImpl)
86 defer parentSpan.Finish()
87
88 span1 := tracer.StartSpan("child", ChildOf(parentSpan.Context())).(*spanImpl)
89 defer span1.Finish()
90
91 require.Equal(t, 1, len(span1.references))
92 require.Equal(t, parentSpan.context.traceID, span1.context.traceID)
93 require.Equal(t, parentSpan.context.spanID, span1.context.parentID)
94
95 ctx := ContextWithSpan(context.Background(), span1)
96 span2 := SpanFromContext(ctx).(*spanImpl)
97
98 span3, _ := StartSpanFromContext(ctx, "child of span")
99 cs := span3.(*spanImpl)
100
101 require.Equal(t, span1, span2)
102 require.Equal(t, 1, len(cs.references))
103 require.Equal(t, span1.context.traceID, cs.context.traceID)
104 require.Equal(t, span1.context.spanID, cs.context.parentID)
105
106 newParentSpan := tracer.StartSpan("newParentSpan")
107 span4 := tracer.StartSpan("nChild", FollowsFrom(span3.Context()),
108 FollowsFrom(newParentSpan.Context())).(*spanImpl)
109
110 require.Equal(t, 2, len(span4.references))
111
112 span5 := tracer.StartSpan("empty span context", ChildOf(&SpanContext{})).(*spanImpl)
113 require.Equal(t, 0, len(span5.references))
114}
115
116func TestStartSpanFromContext(t *testing.T) {
117 span, ctx := StartSpanFromContext(context.Background(), "span1")

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
StartSpanMethod · 0.95
NewTracerFunction · 0.85
ContextWithSpanFunction · 0.85
SpanFromContextFunction · 0.85
StartSpanFromContextFunction · 0.85
FinishMethod · 0.45
ContextMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected