Codebase list golang-github-go-kit-kit / 060a8ce
propagation tests fixed pending change in mocktracer Bas van Beek 7 years ago
3 changed file(s) with 31 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3232 if want, have := "testOp", endpointSpan.OperationName; want != have {
3333 t.Fatalf("Want %q, have %q", want, have)
3434 }
35
35 contextContext := contextSpan.Context().(*mocktracer.MockSpanContext)
36 endpointContext := endpointSpan.Context().(*mocktracer.MockSpanContext)
3637 // ...and that the ID is unmodified.
37 if want, have := contextSpan.SpanID, endpointSpan.SpanID; want != have {
38 if want, have := contextContext.SpanID, endpointContext.SpanID; want != have {
3839 t.Errorf("Want SpanID %q, have %q", want, have)
3940 }
4041 }
8485 t.Fatalf("Want %q, have %q", want, have)
8586 }
8687
88 parentContext := parentSpan.Context().(*mocktracer.MockSpanContext)
89 endpointContext := parentSpan.Context().(*mocktracer.MockSpanContext)
90
8791 // ... and that the parent ID is set appropriately.
88 if want, have := parentSpan.SpanID, endpointSpan.ParentID; want != have {
92 if want, have := parentContext.SpanID, endpointContext.SpanID; want != have {
8993 t.Errorf("Want ParentID %q, have %q", want, have)
9094 }
9195 }
77 "golang.org/x/net/context"
88 "google.golang.org/grpc/metadata"
99
10 "github.com/go-kit/kit/log"
1011 kitot "github.com/go-kit/kit/tracing/opentracing"
1112 )
1213
1314 func TestTraceGRPCRequestRoundtrip(t *testing.T) {
15 logger := log.NewNopLogger()
1416 tracer := mocktracer.New()
1517
1618 // Initialize the ctx with a Span to inject.
1719 beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan)
1820 defer beforeSpan.Finish()
19 beforeSpan.SetBaggageItem("baggage", "check")
21 beforeSpan.Context().SetBaggageItem("baggage", "check")
2022 beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan)
2123
22 toGRPCFunc := kitot.ToGRPCRequest(tracer, nil)
24 toGRPCFunc := kitot.ToGRPCRequest(tracer, logger)
2325 md := metadata.Pairs()
2426 // Call the RequestFunc.
2527 afterCtx := toGRPCFunc(beforeCtx, &md)
3739 }
3840
3941 // Use FromGRPCRequest to verify that we can join with the trace given MD.
40 fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", nil)
42 fromGRPCFunc := kitot.FromGRPCRequest(tracer, "joined", logger)
4143 joinCtx := fromGRPCFunc(afterCtx, &md)
4244 joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan)
4345
44 if joinedSpan.SpanID == beforeSpan.SpanID {
45 t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID)
46 joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext)
47 beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext)
48
49 if joinedContext.SpanID == beforeContext.SpanID {
50 t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID)
4651 }
4752
4853 // Check that the parent/child relationship is as expected for the joined span.
49 if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have {
54 if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have {
5055 t.Errorf("Want ParentID %q, have %q", want, have)
5156 }
5257 if want, have := "joined", joinedSpan.OperationName; want != have {
5358 t.Errorf("Want %q, have %q", want, have)
5459 }
55 if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have {
60 if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have {
5661 t.Errorf("Want %q, have %q", want, have)
5762 }
5863 }
77 "github.com/opentracing/opentracing-go/mocktracer"
88 "golang.org/x/net/context"
99
10 "github.com/go-kit/kit/log"
1011 kitot "github.com/go-kit/kit/tracing/opentracing"
1112 )
1213
1314 func TestTraceHTTPRequestRoundtrip(t *testing.T) {
15 logger := log.NewNopLogger()
1416 tracer := mocktracer.New()
1517
1618 // Initialize the ctx with a Span to inject.
1719 beforeSpan := tracer.StartSpan("to_inject").(*mocktracer.MockSpan)
1820 defer beforeSpan.Finish()
19 beforeSpan.SetBaggageItem("baggage", "check")
21 beforeSpan.Context().SetBaggageItem("baggage", "check")
2022 beforeCtx := opentracing.ContextWithSpan(context.Background(), beforeSpan)
2123
22 toHTTPFunc := kitot.ToHTTPRequest(tracer, nil)
24 toHTTPFunc := kitot.ToHTTPRequest(tracer, logger)
2325 req, _ := http.NewRequest("GET", "http://test.biz/url", nil)
2426 // Call the RequestFunc.
2527 afterCtx := toHTTPFunc(beforeCtx, req)
3739 }
3840
3941 // Use FromHTTPRequest to verify that we can join with the trace given a req.
40 fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", nil)
42 fromHTTPFunc := kitot.FromHTTPRequest(tracer, "joined", logger)
4143 joinCtx := fromHTTPFunc(afterCtx, req)
4244 joinedSpan := opentracing.SpanFromContext(joinCtx).(*mocktracer.MockSpan)
4345
44 if joinedSpan.SpanID == beforeSpan.SpanID {
45 t.Error("SpanID should have changed", joinedSpan.SpanID, beforeSpan.SpanID)
46 joinedContext := joinedSpan.Context().(*mocktracer.MockSpanContext)
47 beforeContext := beforeSpan.Context().(*mocktracer.MockSpanContext)
48
49 if joinedContext.SpanID == beforeContext.SpanID {
50 t.Error("SpanID should have changed", joinedContext.SpanID, beforeContext.SpanID)
4651 }
4752
4853 // Check that the parent/child relationship is as expected for the joined span.
49 if want, have := beforeSpan.SpanID, joinedSpan.ParentID; want != have {
54 if want, have := beforeContext.SpanID, joinedSpan.ParentID; want != have {
5055 t.Errorf("Want ParentID %q, have %q", want, have)
5156 }
5257 if want, have := "joined", joinedSpan.OperationName; want != have {
5358 t.Errorf("Want %q, have %q", want, have)
5459 }
55 if want, have := "check", joinedSpan.BaggageItem("baggage"); want != have {
60 if want, have := "check", joinedSpan.Context().BaggageItem("baggage"); want != have {
5661 t.Errorf("Want %q, have %q", want, have)
5762 }
5863 }