Fix HttpResponseMessage disposal in mock test setups#643
Merged
Conversation
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update to address feedback on http.route attribute
Fix HttpResponseMessage disposal in mock test setups
Feb 4, 2026
baywet
approved these changes
Feb 4, 2026
|
gavinbarron
added a commit
that referenced
this pull request
Feb 6, 2026
* feat: add http.route attribute to open telemetry on requests * expanded tests to include some coverage of existing otel instrumentation * Potential fix for pull request finding 'Missing Dispose call on local IDisposable' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/http/httpClient/HttpClientRequestAdapterObservabilityTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix HttpResponseMessage disposal in Moq test setups (#645) * Initial plan * Fix HttpResponseMessage disposal issues in all observability tests Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Wrap HttpResponseMessage instantiation with lambda in Moq ReturnsAsync (#644) * Initial plan * Fix HttpResponseMessage disposal in all ReturnsAsync calls Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Fix HttpResponseMessage disposal in mock test setups (#642) * Initial plan * Fix HttpResponseMessage disposal in remaining test methods Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Fix HttpResponseMessage disposal in mock test setups (#643) * Initial plan * Fix HttpResponseMessage disposal issues in observability tests Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Fix mock response content-type in observability tests (#646) * Initial plan * Fix empty catch blocks by adding proper content-type to mock responses Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * chore: seals the test class because it implements IDisposable * Fix observability test setup to use correct content type (#647) * Initial plan * Fix empty catch blocks by adding explanatory comments Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Fix test setup to avoid exceptions instead of silencing them Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * chore: removes try catch from tests * Deduplicate baseUrlPlaceholder constant in GetNormalizedHttpRoute (#648) * Initial plan * Deduplicate baseUrlPlaceholder constant definition Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * chore: fixes tests definitions Signed-off-by: Vincent Biret <vibiret@microsoft.com> * chore: formatting Signed-off-by: Vincent Biret <vibiret@microsoft.com> * Mark IDisposable test classes as sealed (#649) * Initial plan * refactor: mark IDisposable test classes as sealed Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * cleaned up tests to theories and fixed missing query string cases --------- Signed-off-by: Vincent Biret <vibiret@microsoft.com> Co-authored-by: Vincent Biret <vibiret@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
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.



Six test methods in
HttpClientRequestAdapterObservabilityTests.cswere creatingHttpResponseMessageobjects in Moq setups without proper disposal, causing resource leaks.Changed all instances from direct instantiation to lambda-wrapped factory:
The lambda wrapper ensures Moq creates a fresh instance per invocation and handles disposal correctly.
Affected tests:
SendAsync_CreatesActivityWithUriTemplateTagSendAsync_WithEmptyPath_SetsHttpRouteToRootSendAsync_SetsHttpRequestMethodTagSendAsync_SetsUrlSchemeAndServerAddressTagsSendAsync_WithoutIncludeEUIIAttributes_DoesNotSetUrlFullTagSendAsync_CreatesNestedActivitySpans✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.