mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-10 09:50:58 +02:00
Fix TestWithIDGenerator (#4894)
This commit is contained in:
parent
c921815474
commit
15b3f4d776
@ -1954,25 +1954,29 @@ var _ IDGenerator = (*testIDGenerator)(nil)
|
|||||||
func TestWithIDGenerator(t *testing.T) {
|
func TestWithIDGenerator(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
startTraceID = 1
|
startTraceID = 1
|
||||||
startSpanID = 1
|
startSpanID = 10
|
||||||
numSpan = 10
|
numSpan = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
gen := &testIDGenerator{traceID: startSpanID, spanID: startSpanID}
|
gen := &testIDGenerator{traceID: startTraceID, spanID: startSpanID}
|
||||||
|
|
||||||
for i := 0; i < numSpan; i++ {
|
|
||||||
te := NewTestExporter()
|
te := NewTestExporter()
|
||||||
tp := NewTracerProvider(
|
tp := NewTracerProvider(
|
||||||
WithSyncer(te),
|
WithSyncer(te),
|
||||||
WithIDGenerator(gen),
|
WithIDGenerator(gen),
|
||||||
)
|
)
|
||||||
span := startSpan(tp, "TestWithIDGenerator")
|
for i := 0; i < numSpan; i++ {
|
||||||
got, err := strconv.ParseUint(span.SpanContext().SpanID().String(), 16, 64)
|
func() {
|
||||||
|
_, span := tp.Tracer(t.Name()).Start(context.Background(), strconv.Itoa(i))
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
gotSpanID, err := strconv.ParseUint(span.SpanContext().SpanID().String(), 16, 64)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
want := uint64(startSpanID + i)
|
assert.Equal(t, uint64(startSpanID+i), gotSpanID)
|
||||||
assert.Equal(t, got, want)
|
|
||||||
_, err = endSpan(te, span)
|
gotTraceID, err := strconv.ParseUint(span.SpanContext().TraceID().String(), 16, 64)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, uint64(startTraceID+i), gotTraceID)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user