Add multithreading tests for 5 validation-check tasks (Group 4)#52937
Add multithreading tests for 5 validation-check tasks (Group 4)#52937SimaTian wants to merge 1 commit intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds/validates MSBuild multithreading support for several SDK validation tasks by ensuring they are marked as multi-threadable and by adding unit tests that assert the required attribute is present. The PR also introduces MSBuild TaskEnvironment-related polyfill types (NETFRAMEWORK-only) plus a test helper to construct TaskEnvironment instances for unit testing.
Changes:
- Add
[MSBuildMultiThreadableTask]toCheckForUnsupportedWinMDReferences. - Add multi-threading unit tests that assert the target tasks are decorated with
MSBuildMultiThreadableTaskAttribute. - Add NETFRAMEWORK-only polyfills for
IMultiThreadableTask/TaskEnvironment/AbsolutePathand supporting driver types, plus a test helper forTaskEnvironment.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWinMDReferences.cs | Marks the task as multi-threadable via attribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACheckForDuplicateFrameworkReferencesMultiThreading.cs | Test asserting the task has MSBuildMultiThreadableTaskAttribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACheckForImplicitPackageReferenceOverridesMultiThreading.cs | Test asserting the task has MSBuildMultiThreadableTaskAttribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACheckForUnsupportedWinMDReferencesMultiThreading.cs | Test asserting the task has MSBuildMultiThreadableTaskAttribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACheckIfPackageReferenceShouldBeFrameworkReferenceMultiThreading.cs | Test asserting the task has MSBuildMultiThreadableTaskAttribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACollatePackageDownloadsMultiThreading.cs | Test asserting the task has MSBuildMultiThreadableTaskAttribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs | Test helper to construct TaskEnvironment instances (via reflection/DispatchProxy). |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelperTests.cs | Unit tests validating the helper’s ProjectDirectory and path resolution behavior. |
| src/Tasks/Common/IMultiThreadableTask.cs | NETFRAMEWORK-only polyfill for MSBuild IMultiThreadableTask. |
| src/Tasks/Common/TaskEnvironment.cs | NETFRAMEWORK-only polyfill for MSBuild TaskEnvironment. |
| src/Tasks/Common/ITaskEnvironmentDriver.cs | NETFRAMEWORK-only polyfill interface supporting TaskEnvironment. |
| src/Tasks/Common/ProcessTaskEnvironmentDriver.cs | NETFRAMEWORK-only driver implementation for TaskEnvironment. |
| src/Tasks/Common/AbsolutePath.cs | NETFRAMEWORK-only polyfill for MSBuild AbsolutePath. |
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelperTests.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACollatePackageDownloadsMultiThreading.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks/CheckForUnsupportedWinMDReferences.cs
Show resolved
Hide resolved
fb150f5 to
b1304be
Compare
SimaTian
left a comment
There was a problem hiding this comment.
Addressed review comments:
- Unused using: Removed
using Microsoft.Build.Frameworkfrom TaskEnvironmentHelperTests.cs. - TestDriverProxy: Changed from
publictointernal. - Blank lines: Added missing blank lines in GivenACollatePackageDownloadsMultiThreading.cs.
- PR description scope: This PR targets
multithreading-polyfills, so diff against main includes polyfill files from base PR (#52909). The actual changes are test files + one task source change.
Branch rebased on updated polyfills and force-pushed.
b1304be to
78658ab
Compare
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenPreMigratedTasksMultiThreading.cs
Outdated
Show resolved
Hide resolved
| var startInfo = new ProcessStartInfo | ||
| { | ||
| WorkingDirectory = _projectDirectory.Value, | ||
| }; | ||
|
|
||
| // Populate environment from the scoped environment dictionary | ||
| foreach (var kvp in _environmentVariables) | ||
| { | ||
| startInfo.EnvironmentVariables[kvp.Key] = kvp.Value; | ||
| } | ||
|
|
There was a problem hiding this comment.
ProcessStartInfo defaults to UseShellExecute=true on .NET Framework; when UseShellExecute is true, environment-variable changes via EnvironmentVariables are not supported and can cause process start failures. Since this method populates EnvironmentVariables, set UseShellExecute=false on the returned ProcessStartInfo.
78658ab to
11bb764
Compare
94d861d to
92c9096
Compare
- Add [MSBuildMultiThreadableTask] attribute to CheckForUnsupportedWinMDReferences - Add GivenPreMigratedTasksMultiThreading.cs with comprehensive multithreading tests for 5 pre-migrated tasks: CheckForDuplicateFrameworkReferences, CheckForDuplicateItemMetadata, CheckForDuplicateItems, CheckForImplicitPackageReferenceOverrides, CollatePackageDownloads - Add TaskEnvironmentHelper and TaskEnvironmentHelperTests for ITaskEnvironment discovery - Add TaskTestEnvironment mock for multi-node MSBuild CWD simulation - Add GivenTasksUseAbsolutePaths.cs with No File I/O tests for group-4 tasks: CheckForDuplicateFrameworkReferences, CheckForDuplicateItemMetadata, CheckForDuplicateItems, CheckForImplicitPackageReferenceOverrides, CheckIfPackageReferenceShouldBeFrameworkReference, CollatePackageDownloads
92c9096 to
3bf923a
Compare
Squashed merge of 5 multithreading test additions for validation-check tasks.
Stacked on #52909 (multithreading-polyfills).
Tasks (test-only, no source changes needed for 4 of 5)
Changes (6 files)
5 new multithreading stress test files + 1 source change:
These tasks already had \IMultiThreadableTask\ on the polyfills branch. This commit adds multithreading unit tests to verify thread safety.
Test Results
5 passed, 0 failed (multithreading tests only).
Build and full test suite succeed.