Fix AppContext switch race in unit tests - #4495
Open
paulmedynski wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request addresses an xUnit parallelism race in the UnitTests project where tests temporarily mutating cached, process-wide AppContext switch values could be observed by concurrently running simulated-server failover tests.
Changes:
- Introduces two non-parallel xUnit collections to isolate (1) AppContext switch mutation and (2) simulated-server tests that may trigger switch-mutation scenarios.
- Assigns
LocalAppContextSwitchesHelperusers to the AppContext isolation collection to prevent cross-test interference. - Makes
TransientFault_ShouldConnectToPrimaryexplicitly opt out of inheriting a process-wide default by settingMultiSubnetFailover = false.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/UnitTests/TestIsolationCollections.cs | Adds new xUnit collection definitions to disable parallelization for AppContext-switch tests and simulated-server tests. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs | Moves the simulated-server suite onto the new non-parallel collection and pins MultiSubnetFailover=false for a specific scenario. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionOptionsTest.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionInternalTimeoutTests.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolIdleTimeoutTest.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolBudgetTest.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolWarmupTest.cs | Assigns test class to AppContext switch isolation collection. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolTest.cs | Assigns test class to AppContext switch isolation collection. |
paulmedynski
marked this pull request as ready for review
July 31, 2026 15:24
paulmedynski
enabled auto-merge (squash)
July 31, 2026 15:24
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4495 +/- ##
==========================================
- Coverage 64.67% 62.81% -1.87%
==========================================
Files 288 283 -5
Lines 44046 66979 +22933
==========================================
+ Hits 28488 42072 +13584
- Misses 15558 24907 +9349
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a unit-test race where
SqlConnectionOptionsTesttemporarily enables the process-wide cachedEnableMultiSubnetFailoverByDefaultswitch while simulated-server failover tests run concurrently.LocalAppContextSwitchesHelperusers to the AppContext isolation collection.MultiSubnetFailover = falseinTransientFault_ShouldConnectToPrimaryso the scenario does not inherit the process-wide default.Issues
Investigated from CI-SqlClient-Package run 21207.
Testing
Checklist