You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +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:
@@ -83,7 +83,7 @@ func TestRegisterSpanProcessor(t *testing.T) {
|
||||
TraceID: tid,
|
||||
SpanID: sid,
|
||||
})
|
||||
ctx := trace.ContextWithRemoteSpanContext(context.Background(), parent)
|
||||
ctx := trace.ContextWithRemoteSpanContext(t.Context(), parent)
|
||||
|
||||
tr := tp.Tracer("SpanProcessor")
|
||||
_, span := tr.Start(ctx, "OnStart")
|
||||
@@ -152,14 +152,14 @@ func TestUnregisterSpanProcessor(t *testing.T) {
|
||||
}
|
||||
|
||||
tr := tp.Tracer("SpanProcessor")
|
||||
_, span := tr.Start(context.Background(), "OnStart")
|
||||
_, span := tr.Start(t.Context(), "OnStart")
|
||||
span.End()
|
||||
for _, sp := range sps {
|
||||
tp.UnregisterSpanProcessor(sp)
|
||||
}
|
||||
|
||||
// start another span after unregistering span processor.
|
||||
_, span = tr.Start(context.Background(), "Start span after unregister")
|
||||
_, span = tr.Start(t.Context(), "Start span after unregister")
|
||||
span.End()
|
||||
|
||||
for _, sp := range sps {
|
||||
@@ -183,7 +183,7 @@ func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) {
|
||||
tp.RegisterSpanProcessor(sp)
|
||||
|
||||
tr := tp.Tracer("SpanProcessor")
|
||||
_, span := tr.Start(context.Background(), "OnStart")
|
||||
_, span := tr.Start(t.Context(), "OnStart")
|
||||
tp.UnregisterSpanProcessor(sp)
|
||||
|
||||
span.End()
|
||||
@@ -208,7 +208,7 @@ func TestSpanProcessorShutdown(t *testing.T) {
|
||||
tp.RegisterSpanProcessor(sp)
|
||||
|
||||
wantCount := 1
|
||||
err := sp.Shutdown(context.Background())
|
||||
err := sp.Shutdown(t.Context())
|
||||
if err != nil {
|
||||
t.Error("Error shutting the testSpanProcessor down\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user