Skip to content

Tests | Address additional flaky tests#4305

Open
edwardneal wants to merge 7 commits into
dotnet:mainfrom
edwardneal:tests/flaky-tests
Open

Tests | Address additional flaky tests#4305
edwardneal wants to merge 7 commits into
dotnet:mainfrom
edwardneal:tests/flaky-tests

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

Description

This corrects a number of other flaky tests which I noticed while looking at the XEvents tests; these fixes are small enough to bundle together.

LocalAppContextSwitchesTest

This is a standalone test, in an assembly where tests in the same class run in sequence, and classes run in parallel. That presents a problem if the AppContext switch tests are running in parallel with tests in ConnectionFailoverTests or SqlConnectionOptionsTest.

LocalAppContextSwitchesTest can find itself in a position where it's asserting EnableMultiSubnetFailoverByDefault or IgnoreServerProvidedFailoverPartner at the same time that SqlConnectionOptionsTest.TestDefaultMultiSubnetFailover or ConnectionFailoverTests.TransientFault_IgnoreServerProvidedFailoverPartner_ShouldConnectToUserProvidedPartner are setting these switches to true.

LocalAppContextSwitchesHelper has its own way to deal with this - a static SemaphoreSlim which only allows one writer at a time. I've chosen to use this in order to maintain consistency when dealing with AppContext switches.

BatchTests.ParameterInOutAndReturn

This test manually created a stored procedure with a hardcoded name. There were a few instances where this already existed. I've replaced this with the StoredProcedure RAII primitive.

AKVUnitTests, EnclaveAzureDatabaseTests

Surprisingly, it looks like there have been occasions where a deleted key with the same name already existed. I've switched the RNG to a more robust implementation, and added some limited retry logic.

The simpler solution would probably have been to purge the key and retry, but I'm not sure what permissions this runs with in CI, and if the key has been deleted then there's no point - it'll be purged in due course.

It's also worth noting the differing approach to generating key names. This is because AKV names have different requirements to database objects.

SqlCommandCancelTest

This depended upon always catching a SqlException when an operation was cancelled. Sometimes this can be an InvalidOperationException.

Issues

None.

Testing

Modified tests continue to pass.

This prevents checks of the default AppContext switch values which would run in parallel to other tests which modify these values via the RAII helper.
* Swap System.Random with the same RNG which SqlClient uses.
* Make a fixed number of attempts to reattempt key creation if a key with the generated name already exists.
@edwardneal edwardneal requested a review from a team as a code owner May 21, 2026 18:49
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 21, 2026
Copy link
Copy Markdown
Contributor

@mdaigle mdaigle left a comment

Choose a reason for hiding this comment

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

🚀

@mdaigle mdaigle added this to the 7.1.0-preview2 milestone May 22, 2026
@mdaigle mdaigle assigned mdaigle and benrr101 and unassigned mdaigle May 22, 2026
@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented May 22, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

3 participants