Skip to content

Fix flaky DistributedFileLoggerParameters test by isolating log files in TEMP#13704

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-distributed-file-logger-test
Open

Fix flaky DistributedFileLoggerParameters test by isolating log files in TEMP#13704
Copilot wants to merge 2 commits intomainfrom
copilot/fix-distributed-file-logger-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Context

FileLogger_Tests.DistributedFileLoggerParameters intermittently failed with LoggerException: Failed to write to log file "msbuild0.log"... it is being used by another process against a path inside the test bin folder.

The first iteration calls Initialize with no Parameters, so DistributedFileLogger defaults to msbuild0.log in Directory.GetCurrentDirectory() — i.e. the test bin directory. The finally block tried to delete mylogfile0.log (a name that never existed), so msbuild0.log leaked between runs and was vulnerable to transient locks from antivirus, search indexers, or other processes scanning the bin output.

Changes Made

Rewrote the test using TestEnvironment and modernized per tests.instructions.md:

  • Added an ITestOutputHelper constructor; pass _output to TestEnvironment.Create.
  • Created a TransientTestFolder under TEMP and set it as the current directory via env.SetCurrentDirectory, so the implicit msbuild0.log and all explicit log paths resolve into the transient folder and get auto-cleaned on dispose. Removed the manual try/finally cleanup.
  • Used folder.CreateDirectory("tempura") for the nested-subfolder case instead of Directory.CreateDirectory + manual delete.
  • Replaced Assert.Equal(0, string.Compare(..., StringComparison.OrdinalIgnoreCase)) with ShouldBe(..., StringCompareShould.IgnoreCase).

Testing

DistributedFileLoggerParameters and the rest of FileLogger_Tests pass locally (the unrelated InvalidFile test remains skipped on Linux via its existing trait).

Notes

Other hypotheses considered and ruled out: reuse of the fileLogger instance across iterations (each Shutdown() properly closes the writer) and stale _logFile state (the Parameters setter re-parses on each Initialize). The leaked msbuild0.log in the bin directory is the only plausible flakiness vector, and isolating to a per-test TEMP folder removes it.

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

…nt temp folder

Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/34c84440-a320-492f-971d-81aa53507443

Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flaky DistributedFileLoggerParameters test Fix flaky DistributedFileLoggerParameters test by isolating log files in TEMP May 6, 2026
Copilot AI requested a review from rainersigwald May 6, 2026 16:53
@rainersigwald rainersigwald marked this pull request as ready for review May 6, 2026 21:26
Copilot AI review requested due to automatic review settings May 6, 2026 21:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes flakiness in FileLogger_Tests.DistributedFileLoggerParameters by ensuring default/implicit log files (like msbuild0.log) are created in a per-test transient TEMP directory rather than the test bin folder, reducing susceptibility to transient file locks from external processes.

Changes:

  • Updated DistributedFileLoggerParameters to use TestEnvironment + a TransientTestFolder and set it as the current directory for the test.
  • Removed manual cleanup logic in favor of TestEnvironment-managed cleanup and switched string comparisons to Shouldly.

Comment thread src/Build.UnitTests/FileLogger_Tests.cs
@rainersigwald rainersigwald enabled auto-merge (squash) May 6, 2026 21:45
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.

DistributedFileLoggerParameters flaky test

3 participants