in testutils/testtracing/propagation.go [238:302]
func (s *PropagationTestSuite) runTestCase(
t *testing.T,
tracer tracerChoice,
ch *tchannel.Channel,
test PropagationTestCase,
call TracingCall,
) {
descr := fmt.Sprintf("test %+v with tracer %+v", test, tracer)
ch.Logger().Debugf("Starting tracing test %s", descr)
tracer.resetSpans()
span := ch.Tracer().StartSpan("client")
span.SetBaggageItem(BaggageKey, BaggageValue)
ctx := opentracing.ContextWithSpan(context.Background(), span)
ctxBuilder := tchannel.NewContextBuilder(5 * time.Second).SetParentContext(ctx)
if test.TracingDisabled {
ctxBuilder.DisableTracing()
}
ctx, cancel := ctxBuilder.Build()
defer cancel()
req := &TracingRequest{ForwardCount: test.ForwardCount}
ch.Logger().Infof("Sending tracing request %+v", req)
response, err := call(ctx, req)
require.NoError(t, err)
ch.Logger().Infof("Received tracing response %+v", response)
// Spans are finished in inbound.doneSending() or outbound.doneReading(),
// which are called on different go-routines and may execute *after* the
// response has been received by the client. Give them a chance to run.
for i := 0; i < 1000; i++ {
if spanCount := tracer.spansRecorded(); spanCount == test.ExpectedSpanCount {
break
}
time.Sleep(testutils.Timeout(time.Millisecond))
}
spanCount := tracer.spansRecorded()
ch.Logger().Debugf("end span count: %d", spanCount)
// finish span after taking count of recorded spans, as we're only interested
// in the count of spans created by RPC calls.
span.Finish()
root := new(TracingResponse).ObserveSpan(ctx)
if !tracer.isFake {
assert.Equal(t, uint64(0), root.ParentID)
assert.NotEqual(t, uint64(0), root.TraceID)
}
assert.Equal(t, test.ExpectedSpanCount, spanCount, "Wrong span count; %s", descr)
for r, cnt := response, 0; r != nil || cnt <= test.ForwardCount; r, cnt = r.Child, cnt+1 {
require.NotNil(t, r, "Expecting response for forward=%d; %s", cnt, descr)
if !tracer.isFake {
if tracer.zipkinCompatible || s.Encoding.HeadersSupported {
assert.Equal(t, root.TraceID, r.TraceID, "traceID should be the same; %s", descr)
}
assert.Equal(t, test.ExpectedBaggage, r.Luggage, "baggage should propagate; %s", descr)
}
}
ch.Logger().Debugf("Finished tracing test %s", descr)
}