Fix debugging task test SDK state leak - #12603
Merged
Merged
Conversation
Restore process environment variables and Xamarin.AndroidTools SDK singletons after TestResolveToolsExists uses temporary SDK fixtures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the existing test setup intact and restore only JAVA_HOME, PATH, and AndroidSdk state after executing the task. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Fixes a deterministic Windows test-suite contamination where DebuggingTasksTests.TestResolveToolsExists mutates process environment variables and shared Xamarin.AndroidTools SDK singletons, leaving later tests with stale SDK/JDK paths after the test’s temporary directories are deleted.
Changes:
- Snapshot
JAVA_HOME/PATHand Android/MonoDroid SDK singleton state before runningResolveXamarinAndroidTools. - Restore SDK singletons and environment variables in a
finallyblock to prevent cross-test leakage. - Add post-restore assertions (within the repeated test) to verify state is reset after each run.
File summaries
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DebuggingTasksTests.cs | Adds state capture + finally restoration of Android/MonoDroid SDK singletons and JAVA_HOME/PATH, with assertions to prevent future state leaks. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Keep existing assertions outside the cleanup block so the final diff only wraps the calls that mutate process-wide SDK state. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
rolfbjarne
approved these changes
Sep 1, 2026
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.
Description
DebuggingTasksTests.TestResolveToolsExistsinvokesResolveXamarinAndroidToolswith temporary Android and Java SDK directories. On Windows,AndroidSdkWindows.Initialize()updates process-levelJAVA_HOMEandPATH, andAndroidSdk.Refresh()leaves shared SDK state pointing at the temporary fixtures. After those directories are deleted, later tests such asPackagingTest.CheckSignApk(False,False,NativeAOT)can launch Android tooling with the stale JDK path.Capture the real SDK paths and original process environment immediately before task execution. A focused
try/finallyaround the two task calls restoresAndroidSdk,JAVA_HOME, andPATH; the existing test setup and cache assertions remain otherwise unchanged.This is a standalone fix for the deterministic Windows CI contamination observed in PR #12554 build 1571801; it does not modify or depend on the Dependabot change.
Testing
dotnet-local.cmd build src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj -v:quietdotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "Name~TestResolveToolsExists" -v:quiet