Fix flaky test: eliminate parallel build conflict in TestDiscoveryWarningsTests#7532
Conversation
…to avoid parallel build conflict Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
|
@copilot tests are failing: |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryWarningsTests.cs
Show resolved
Hide resolved
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
... Fixed in 18b9e19. The issue was that MSBuild's default |
There was a problem hiding this comment.
Pull request overview
Fixes intermittent TestDiscoveryWarningsTests failures caused by TestAssetFixtureBase.InitializeAsync building multiple generated assets in parallel while one asset had a ProjectReference to another, leading to concurrent MSBuild writes (file locking).
Changes:
- Stops generating
TestDiscoveryWarningsBaseClassas a separate asset; instead embeds it as a subdirectory within theTestDiscoveryWarningsasset so only one explicit build runs. - Updates the
ProjectReferencepath to the new in-asset location. - Removes the now-unused
BaseTargetAssetPathandBaseClassSourceCodeconstant by folding base-class files into the mainSourceCodeasset string.
You can also share your feedback on Copilot code review. Take the survey.
| <ItemGroup> | ||
| <ProjectReference Include="../TestDiscoveryWarningsBaseClass/TestDiscoveryWarningsBaseClass.csproj" /> | ||
| <ProjectReference Include="TestDiscoveryWarningsBaseClass/TestDiscoveryWarningsBaseClass.csproj" /> | ||
| <Compile Remove="TestDiscoveryWarningsBaseClass/**" /> |
There was a problem hiding this comment.
<Compile Remove="TestDiscoveryWarningsBaseClass/**" /> uses a very broad glob that will enumerate all files under that subtree (including bin/obj once they exist) during MSBuild evaluation. Since the intent is only to prevent the main project from compiling the nested base-class sources, restrict the remove pattern to C# sources (e.g., **/*.cs) to avoid unnecessary filesystem scanning and accidental future removals if default items change.
| <Compile Remove="TestDiscoveryWarningsBaseClass/**" /> | |
| <Compile Remove="TestDiscoveryWarningsBaseClass/**/*.cs" /> |
TestDiscoveryWarningsTestswas intermittently failing with file-locking errors (IOException: The process cannot access the file ... because it is being used by another process) becauseTestAssetFixtureBase.InitializeAsyncbuilds all assets in parallel, andTestDiscoveryWarningshas aProjectReferencetoTestDiscoveryWarningsBaseClass— so both parallel builds raced to write the same output files.Changes
TestDiscoveryWarningsBaseClassas a subdirectory within theTestDiscoveryWarningsasset instead of yielding it as a separate asset fromGetAssetsToGenerate. Only one explicit build is now triggered; MSBuild handles the base class as a project reference dependency.ProjectReferencefrom../TestDiscoveryWarningsBaseClass/...toTestDiscoveryWarningsBaseClass/...to reflect the new relative path.BaseTargetAssetPathproperty andBaseClassSourceCodeconstant.Before (two parallel builds → race condition):
After (single build, base class as subdirectory):
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.