Skip to content

[Microsoft.Android.Run] Delete the pulled device TRX after parsing - #13601

Merged
simonrozsival merged 1 commit into
mainfrom
jonathanpeppers-fix-stray-androidtest-trx
Nov 18, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
jonathanpeppers-fix-stray-androidtest-trx

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1685875&view=ms.vss-test-web.build-test-results-tab
Context: f72b411

The Mac - .NET job of the xamarin_android_tools_tests stage published an extra test run with two tests, Tests.One (passed) and Tests.Two (failed). The dotnet test output for the same job showed no failures:

Passed!  - Failed:     0, Passed:   166, Skipped:     4, Total:   170, Duration: 9 s - Microsoft.Android.Build.BaseTasks-Tests.dll (net11.0)
Passed!  - Failed:     0, Passed:   447, Skipped:     8, Total:   455, Duration: 16 s - Xamarin.Android.Tools.AndroidSdk-Tests.dll (net11.0)

StreamingTests.InstrumentationWithoutStreamingReportsResultsFromTrx uses a fake adb that returns a hard-coded TRX file with these two results. AndroidTestAdapter.PullTrxFileAsync() copies that file to $TMPDIR/AndroidTestResults/<package>/device.trx, and nothing deletes it. On the agent, $TMPDIR is _work/_temp, which is also the --results-directory that DotNetCoreCLI@2 searches for *.trx files to publish. The test is ignored on Windows, so only the Mac job showed the problem.

Delete the local TRX copy after it is parsed. The adapter only needs the parsed results, and --report-trx writes the real report. This also stops dotnet test from leaving TRX files in the user's temp directory.

Validation:

  • dotnet build tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -c Debug -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=11.0: succeeded, 0 warnings.
  • dotnet build src/Microsoft.Android.Run/Microsoft.Android.Run.csproj -c Debug: succeeded, 0 warnings.
  • InstrumentationWithoutStreamingReportsResultsFromTrx now asserts that the pulled file is gone. I did not run it locally because it is ignored on Windows; the Mac CI job runs it.

AndroidTestAdapter.PullTrxFileAsync copies the device TRX to
\/AndroidTestResults/<package>/. The file was never deleted.

On CI agents, TMPDIR is the agent temp directory, and DotNetCoreCLI@2
publishes every *.trx file in that directory. The fake TRX from
StreamingTests.InstrumentationWithoutStreamingReportsResultsFromTrx
was published as an extra test run with a failed Tests.Two.

Delete the local copy after it is parsed.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the temporary TRX cleanup change.

No open issues 🎉

What changed in this PR

This PR cleans up temporary device TRX files after parsing in Microsoft.Android.Run, preventing CI from publishing them as duplicate test runs.

Changes:

  • Deletes the pulled TRX file in a finally block, including when parsing fails.
  • Extends the existing instrumentation test to assert that the temporary file is removed.
File Description
tests/​Xamarin.Android.Tools.AndroidSdk-Tests/​StreamingTests.cs Adds an assertion verifying temporary TRX cleanup.
src/​Microsoft.Android.Run/​AndroidTestAdapter.cs Deletes the local device TRX copy after parsing.

Review effort: Balanced

@simonrozsival
simonrozsival merged commit 8442c75 into main Nov 18, 2026
39 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-fix-stray-androidtest-trx branch November 18, 2026 14:48
simonrozsival added a commit that referenced this pull request Nov 21, 2026
The rebase onto cc7cbf6 kept the pre-rebase MSTest conversions of
files that main had changed since aa688ac, which reverted those
changes and broke the build. For each affected file, convert main's
old and new NUnit versions with the same converter and merge the
difference into the MSTest file:

  * cca255c (#13592): drop the Android lint tests and assertions.
  * 5b32fb1 (#13602): add RelativeDirectoriesUseProjectDirectory and
    the -mt CollectNonEmptyDirectories coverage.
  * 78ef747 (#13655): add OpenGenericProxiesKeepTheReflectionActivationConstructor.
  * 18b8940 (#13585): add the generator nullability/obsolete tests.
  * dcbd008 (#13580): add the AmbiguousFunctionMetadata_* tests.
  * 667e27a (#13621): add the sdkmanager package ID tests.
  * 5ecb8f7 (#13614): drop RunWithLoggingEnablesManagedTimingLogger.
  * 8287b17 (#13680), 4bfcc92 (#13681): restore the re-enabled
    tests and removed TODOs.
  * 5d81a0f (#13666): expect platform-tools 37.0.3.
  * 8442c75 (#13601): assert the pulled device TRX is deleted.

Also drop the EnableNUnitRunner/OutputType lines that 857f463
(#13563) added to Xamarin.Android.Build.Tests and MSBuildDeviceIntegration;
MSTestReferences.projitems sets both.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants