Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@paulmedynski
Copy link
Contributor

@paulmedynski paulmedynski commented Dec 17, 2025

Description

  • Eliminated most race conditions when using the LocalAppContextSwitchesHelper.
  • Cleaned up the Helper class to reduce maintenance burden.
  • Consolidated switch value acquisition to avoid copy-pasta code.
  • Re-order the switches alphabetically everywhere for consistency.

TODO:

  • Tidy up the switch property comments.

The first 4 commits can be reviewed together. The remaining commits (that do the cleanup work) are best reviewed individually.

Testing

PR and CI pipelines will test this. The failures have been intermittent, so it may take a few runs even after this hits main to declare it fixed.

…lper.

- Removed Tristate in favour of bool?.
- Gave the Common test project access to MDS internals and cleaned up the Helper a lot.
@paulmedynski paulmedynski requested a review from a team as a code owner December 17, 2025 22:30
Copilot AI review requested due to automatic review settings December 17, 2025 22:30
Copy link
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 refactors the LocalAppContextSwitchesHelper to eliminate race conditions and simplify the implementation. The changes replace the custom Tristate enum with nullable bool (bool?), remove reflection-based field access in favor of direct access via InternalsVisibleTo, and introduce a semaphore-based locking mechanism to ensure only one test helper instance exists at a time. The Common test project now has access to Microsoft.Data.SqlClient internals, and nullable reference types have been enabled for better null safety.

Key Changes

  • Replaced Tristate enum with bool? throughout LocalAppContextSwitches and test helper code
  • Introduced semaphore-based mutual exclusion to prevent concurrent LocalAppContextSwitchesHelper instances
  • Granted Common test project access to MDS internals via InternalsVisibleTo, eliminating need for reflection

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs Removed Tristate enum, changed fields from private to internal, converted all switch backing fields to bool?
src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs Replaced reflection-based access with direct field access, added semaphore locking, renamed properties from *Field to *Value suffix
src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionTests.cs Updated test code to use new property names (EnableUserAgentValue instead of EnableUserAgentField)
src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs Updated test code to use new property naming convention with Value suffix
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlConnectionStringTest.cs Converted Tristate parameters to bool? in test data and updated property references
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs Simplified switch assignments by removing ternary operators converting bool to Tristate
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs Updated legacy row version test helper usage to new bool? based API
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs Simplified legacy scale behavior switch assignment to use bool directly
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/CspCertificateFixture.cs Added nullable annotations for RSA and path properties
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/ColumnMasterKeyCertificateFixture.cs Made certificate property nullable
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/ColumnEncryptionCertificateFixture.cs Added nullable annotation for local machine certificate and improved null handling in GetCertificate
src/Microsoft.Data.SqlClient/tests/Common/Fixtures/CertificateFixtureBase.cs Added nullable annotations for password and store context variables
src/Microsoft.Data.SqlClient/tests/Common/Common.csproj Enabled nullable reference types for the Common test project
src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj Added InternalsVisibleTo for Common test assembly
src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj Added InternalsVisibleTo for Common test assembly

DateTimeOffset notBefore = DateTimeOffset.UtcNow.AddDays(-1);
DateTimeOffset notAfter = DateTimeOffset.UtcNow.AddDays(1);
byte[] passwordBytes = new byte[32];
string password = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I enabled nullable context for the entire Common test project, so there are a few changes like this related to that.

Copilot AI review requested due to automatic review settings December 18, 2025 17:35
Copy link
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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 14 comments.

Copilot AI review requested due to automatic review settings December 18, 2025 19:47
Copy link
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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

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.

4 participants