{{ message }}
[test-improver] Improve tests for tracing package#7740
Merged
lpcox merged 3 commits intoJun 19, 2026
Conversation
Add three new tests to provider_internal_test.go (package tracing): - TestGenerateRandomSpanID: verifies the happy path produces a valid non-zero 8-byte span ID and that successive calls yield distinct values. - TestGenerateRandomSpanID_Error: injects a failing crypto/rand.Reader to cover the error return path (previously at 83.3%). - TestParentContext_RandomSpanIDFailure: triggers the genErr != nil branch in ParentContext by breaking the random source, verifying the original context is returned unchanged (previously uncovered). Coverage improvements for internal/tracing: generateRandomSpanID: 83.3% → 100% ParentContext: 92.6% → 100% package total: 95.2% → 96.2% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage in internal/tracing by adding targeted tests for previously unexercised error paths in span ID generation and ParentContext, improving confidence in tracing initialization behavior.
Changes:
- Added a happy-path test for
generateRandomSpanIDto validate non-zero output. - Added an error-path test for
generateRandomSpanIDby injecting a failing random source. - Added an error-path test for
ParentContextto confirm it returns the original context when span ID generation fails.
Show a summary per file
| File | Description |
|---|---|
| internal/tracing/provider_internal_test.go | Adds tests to cover generateRandomSpanID and ParentContext error branches via injected rand.Reader failures. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
|
@copilot fix the failing ci checks https://github.com/github/gh-aw-mcpg/actions/runs/27800176294/job/82268593878?pr=7740 |
Contributor
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.

Test Improvements:
provider_internal_test.goFile Analyzed
internal/tracing/provider_internal_test.gointernal/tracingImprovements Made
1. Increased Coverage
TestGenerateRandomSpanID: verifies the happy path — produces a valid non-zero 8-byte span ID and that successive calls yield distinct valuesTestGenerateRandomSpanID_Error: injects a failingcrypto/rand.Readerto cover the previously dead error-return path ingenerateRandomSpanIDTestParentContext_RandomSpanIDFailure: triggers thegenErr != nilbranch inParentContext(lines 322–325 ofprovider.go) by breaking the random source, verifying the original context is returned unchangedgenerateRandomSpanIDParentContext2. Better Testing Patterns
errorReaderstruct (same pattern asauth/header_test.go) to test unreachable crypto-failure branchesrand.Readermutation) are explicitly left non-parallel with a comment explaining whyrequire.NoError/require.Errorfor blocking assertions,assert.*for non-blocking checks — consistent with project conventionst.Parallel()on the pure happy-path test that has no global side effectsTest Execution
All tests pass:
Why These Changes?
provider_internal_test.gowas a thin 52-line file that only testedmergeOTLPHeaders. The two functions with coverage gaps —generateRandomSpanID(83.3%) andParentContext(92.6%) — had unreachable error paths that requirecrypto/randfailure injection. Since the test file is in packagetracing(nottracing_test), it has direct access to the unexportedgenerateRandomSpanIDand can inject therand.Readerfailure needed to exercise both error branches. The improvements follow the exact sameerrorReader/rand.Readerswap pattern already established ininternal/auth/header_test.go.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.