You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
refactor: replace context.Background() with t.Context()/b.Context() in tests (#7352)
Based on the Go version we currently use, the dependency already supports 1.24+, which allows using `t.Context()` and `b.Context()` in unit tests and benchmarks respectively. - Enable `context-background` and `context-todo` in [`usetesting`](https://golangci-lint.run/docs/linters/configuration/#usetesting) - Adjust the code to support linter detection --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com> Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package observ_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -70,7 +69,7 @@ func TestTracer(t *testing.T) {
|
||||
collect := setup(t)
|
||||
tracer := trace.NewTracerProvider().Tracer(t.Name())
|
||||
|
||||
_, span := tracer.Start(context.Background(), "span")
|
||||
_, span := tracer.Start(t.Context(), "span")
|
||||
check(t, collect(), sampledLive(1), sampledStarted(1))
|
||||
|
||||
span.End()
|
||||
@@ -95,7 +94,7 @@ func TestTracerNonRecording(t *testing.T) {
|
||||
trace.WithSampler(trace.NeverSample()),
|
||||
).Tracer(t.Name())
|
||||
|
||||
_, _ = tracer.Start(context.Background(), "span")
|
||||
_, _ = tracer.Start(t.Context(), "span")
|
||||
check(t, collect(), dropStarted(1))
|
||||
}
|
||||
|
||||
@@ -138,7 +137,7 @@ func TestTracerRecordOnly(t *testing.T) {
|
||||
trace.WithSampler(recOnly{}),
|
||||
).Tracer(t.Name())
|
||||
|
||||
_, _ = tracer.Start(context.Background(), "span")
|
||||
_, _ = tracer.Start(t.Context(), "span")
|
||||
check(t, collect(), recLive(1), recStarted(1))
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ func TestTracerRemoteParent(t *testing.T) {
|
||||
tracer := trace.NewTracerProvider().Tracer(t.Name())
|
||||
|
||||
ctx := tapi.ContextWithRemoteSpanContext(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
tapi.NewSpanContext(tapi.SpanContextConfig{
|
||||
TraceID: tapi.TraceID{0x01},
|
||||
SpanID: tapi.SpanID{0x01},
|
||||
@@ -195,7 +194,7 @@ func TestTracerLocalParent(t *testing.T) {
|
||||
collect := setup(t)
|
||||
tracer := trace.NewTracerProvider().Tracer(t.Name())
|
||||
|
||||
ctx, parent := tracer.Start(context.Background(), "parent")
|
||||
ctx, parent := tracer.Start(t.Context(), "parent")
|
||||
_, child := tracer.Start(ctx, "child")
|
||||
|
||||
check(t, collect(), sampledLive(2), chainStarted(1, 1))
|
||||
@@ -243,7 +242,7 @@ func BenchmarkTracer(b *testing.B) {
|
||||
require.True(b, tracer.Enabled())
|
||||
|
||||
t := otel.GetTracerProvider().Tracer(b.Name())
|
||||
ctx, span := t.Start(context.Background(), "parent")
|
||||
ctx, span := t.Start(b.Context(), "parent")
|
||||
psc := span.SpanContext()
|
||||
span.End()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user