refactor: replace context.Background() with t.Context()/b.Context() in tests#7352
Merged
dmathieu merged 24 commits intoopen-telemetry:mainfrom Sep 23, 2025
Merged
refactor: replace context.Background() with t.Context()/b.Context() in tests#7352dmathieu merged 24 commits intoopen-telemetry:mainfrom
context.Background() with t.Context()/b.Context() in tests#7352dmathieu merged 24 commits intoopen-telemetry:mainfrom
Conversation
…ground - Replace context.Background() with t.Context() in unit tests - This change ensures that the test uses the context provided by the testing framework, which may contain useful information for the test
- Update multiple test files to use t.Context() instead of context.Background() - This change improves testability by allowing the test framework to control the context - Affected files: - bridge_grpc_test.go - bridge_test.go - metric_test.go - mix_test.go - trace_test.go - tracer_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7352 +/- ##
=======================================
- Coverage 85.5% 85.5% -0.1%
=======================================
Files 275 275
Lines 24614 24614
=======================================
- Hits 21048 21045 -3
- Misses 3187 3190 +3
Partials 379 379 🚀 New features to boost your workflow:
|
context.Background() with t.Context()/b.Context() in testscontext.Background() with t.Context()/b.Context() in tests
Use context.Background() instead of b.Context() when asserting Shutdown in benchmark cleanup to avoid unnecessary overhead and potential panic. - Updated in trace/benchmark_test.go
…or Shutdown - Use context.Background() instead of t.Context() when calling Shutdown- Add inline comment to explain the change and suppress linter warning - Update multiple test functions to use the new approach
context.Background() with t.Context()/b.Context() in testscontext.Background() with t.Context()/b.Context() in tests
dmathieu
reviewed
Sep 12, 2025
- Replace 'used to assert Shutdown' with 'required to avoid getting a canceled context at cleanup' in multiple test files - Update several test files to use context.Background() in Shutdown calls with the new comment - This change improves test cleanup and prevents potential issues with canceled contexts
dmathieu
approved these changes
Sep 15, 2025
XSAM
approved these changes
Sep 15, 2025
MrAlias
approved these changes
Sep 15, 2025
dmathieu
reviewed
Sep 16, 2025
…P client test - Use context.Background() instead of t.Context() to prevent potential context cancellation at cleanup - Add comment explaining the use of context.Background() and ignoring the usetesting linter
# Conflicts: # exporters/otlp/otlptrace/otlptracegrpc/client_test.go
Replace `context.Background()` with `t.Context()` in multiple test files to ensureproper context handling during test cleanup. This change prevents tests from using a background context that may be canceled unexpectedly.Also remove unused import of `context` package in instrumentation_test.go and add nolint comments where necessary to avoid linting errors related to context usage.
dmathieu
approved these changes
Sep 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the Go version we currently use, the dependency already supports 1.24+, which allows using
t.Context()andb.Context()in unit tests and benchmarks respectively.context-backgroundandcontext-todoinusetesting