Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Fix baggage/debug header tests to not defer in loops #315

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,33 +191,33 @@ func TestJaegerBaggageHeader(t *testing.T) {
}

for _, testcase := range testcases {

metricsFactory, metrics := initMetrics()
tracer, closer := NewTracer("DOOP",
NewConstSampler(true),
NewNullReporter(),
TracerOptions.Metrics(metrics),
)
defer closer.Close()

h := http.Header{}
h.Add(JaegerBaggageHeader, "key1=value1, key 2=value two")

ctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
require.NoError(t, err)

sp := tracer.StartSpan("root", testcase.refFunc(ctx)).(*Span)

assert.Equal(t, "value1", sp.BaggageItem("key1"))
assert.Equal(t, "value two", sp.BaggageItem("key 2"))

// ensure that traces.started counter is incremented, not traces.joined
testutils.AssertCounterMetrics(t, metricsFactory,
testutils.ExpectedMetric{
Name: "jaeger.traces", Tags: map[string]string{"state": "started", "sampled": "y"}, Value: 1,
},
)

t.Run("", func(t *testing.T) {
metricsFactory, metrics := initMetrics()
tracer, closer := NewTracer("DOOP",
NewConstSampler(true),
NewNullReporter(),
TracerOptions.Metrics(metrics),
)
defer closer.Close()

h := http.Header{}
h.Add(JaegerBaggageHeader, "key1=value1, key 2=value two")

ctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
require.NoError(t, err)

sp := tracer.StartSpan("root", testcase.refFunc(ctx)).(*Span)

assert.Equal(t, "value1", sp.BaggageItem("key1"))
assert.Equal(t, "value two", sp.BaggageItem("key 2"))

// ensure that traces.started counter is incremented, not traces.joined
testutils.AssertCounterMetrics(t, metricsFactory,
testutils.ExpectedMetric{
Name: "jaeger.traces", Tags: map[string]string{"state": "started", "sampled": "y"}, Value: 1,
},
)
})
}
}

Expand Down Expand Up @@ -258,38 +258,38 @@ func TestDebugCorrelationID(t *testing.T) {
}

for _, testcase := range testcases {

metricsFactory, metrics := initMetrics()
tracer, closer := NewTracer("DOOP",
NewConstSampler(true),
NewNullReporter(),
TracerOptions.Metrics(metrics),
)
defer closer.Close()

h := http.Header{}
val := "value1"
h.Add(JaegerDebugHeader, val)
ctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
require.NoError(t, err)
assert.EqualValues(t, 0, ctx.(SpanContext).parentID)
assert.EqualValues(t, val, ctx.(SpanContext).debugID)
sp := tracer.StartSpan("root", testcase.refFunc(ctx)).(*Span)
assert.EqualValues(t, 0, sp.context.parentID)
assert.True(t, sp.context.traceID.IsValid())
assert.True(t, sp.context.IsSampled())
assert.True(t, sp.context.IsDebug())

tag := findDomainTag(sp, JaegerDebugHeader)
assert.NotNil(t, tag)
assert.Equal(t, val, tag.value)

// ensure that traces.started counter is incremented, not traces.joined
testutils.AssertCounterMetrics(t, metricsFactory,
testutils.ExpectedMetric{
Name: "jaeger.traces", Tags: map[string]string{"state": "started", "sampled": "y"}, Value: 1,
},
)

t.Run("", func(t *testing.T) {
metricsFactory, metrics := initMetrics()
tracer, closer := NewTracer("DOOP",
NewConstSampler(true),
NewNullReporter(),
TracerOptions.Metrics(metrics),
)
defer closer.Close()

h := http.Header{}
val := "value1"
h.Add(JaegerDebugHeader, val)
ctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(h))
require.NoError(t, err)
assert.EqualValues(t, 0, ctx.(SpanContext).parentID)
assert.EqualValues(t, val, ctx.(SpanContext).debugID)
sp := tracer.StartSpan("root", testcase.refFunc(ctx)).(*Span)
assert.EqualValues(t, 0, sp.context.parentID)
assert.True(t, sp.context.traceID.IsValid())
assert.True(t, sp.context.IsSampled())
assert.True(t, sp.context.IsDebug())

tag := findDomainTag(sp, JaegerDebugHeader)
assert.NotNil(t, tag)
assert.Equal(t, val, tag.value)

// ensure that traces.started counter is incremented, not traces.joined
testutils.AssertCounterMetrics(t, metricsFactory,
testutils.ExpectedMetric{
Name: "jaeger.traces", Tags: map[string]string{"state": "started", "sampled": "y"}, Value: 1,
},
)
})
}
}