Skip to content

Resolves the test failure in CanShutdownServerProcess when setting capacity for the _nodeContexts dictionary#12961

Merged
YuliiaKovalova merged 1 commit intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/canshutdownserverprocess-fail-when-nodecontexts-capacity-is-set
Dec 29, 2025
Merged

Resolves the test failure in CanShutdownServerProcess when setting capacity for the _nodeContexts dictionary#12961
YuliiaKovalova merged 1 commit intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/canshutdownserverprocess-fail-when-nodecontexts-capacity-is-set

Conversation

@huulinhnguyen-dev
Copy link
Contributor

Resolves the test failure in CanShutdownServerProcess when setting capacity for the _nodeContexts dictionary #12187

Fixes #12187

Context

When attempting to set capacity for _nodeContexts dictionary to improve performance, the test MSBuildServer_Tests.CanShutdownServerProcess(byBuildManager: True) failed due to NullReferenceException when accessing host.BuildParameters.MaxNodeCount without null-checking.

Changes Made

  • Added null-safe check for host.BuildParameters before accessing MaxNodeCount
  • Validate MaxNodeCount > 0 to avoid invalid capacity values
  • Use Environment.ProcessorCount for concurrencyLevel to optimize multi-threaded scenarios
  • Provide fallback initialization when BuildParameters is null or invalid

Testing

  • Verified MSBuildServer_Tests.CanShutdownServerProcess passes with both byBuildManager: True and False
  • Confirmed the fix enables capacity optimization while maintaining thread-safety

Notes

This change allows performance optimization through pre-allocated dictionary capacity while ensuring test stability and proper null handling.

@huulinhnguyen-dev huulinhnguyen-dev marked this pull request as ready for review December 23, 2025 08:21
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.

Why MSBuildServer_Tests.CanShutdownServerProcess fails when NodeProviderInProc._nodeContexts capacity is set?

2 participants