Tests | Address additional flaky tests#4305
Conversation
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.
…ate operation cancellation
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
LocalAppContextSwitchesHelper was returning the field values, skipping the default values exposed by LocalAppContextSwitches when the AppContext switch had not been set one way or another.
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4305 +/- ##
==========================================
- Coverage 66.57% 65.82% -0.76%
==========================================
Files 284 279 -5
Lines 43301 66219 +22918
==========================================
+ Hits 28827 43586 +14759
- Misses 14474 22633 +8159
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| // These properties get or set the like-named underlying switch field value. | ||
| // These properties get the like-named underlying switch *property* value and set the underlying | ||
| // switch *field* value. This allows tests to verify the default switch values. |
There was a problem hiding this comment.
The getter and setter of these properties isn't identical - we read from them to get the values of the AppContext switches (including any default values/dependencies between properties.) I'm not completely happy with this, but the alternative would be for call sites to instantiate LocalAppContextSwitchesHelper, only to leave it untouched and read property values directly from LocalAppContextSwitches. Doing so doesn't strike me as an obvious way to use the type.
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.
LocalAppContextSwitchesTestThis 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
ConnectionFailoverTestsorSqlConnectionOptionsTest.LocalAppContextSwitchesTestcan find itself in a position where it's assertingEnableMultiSubnetFailoverByDefaultorIgnoreServerProvidedFailoverPartnerat the same time thatSqlConnectionOptionsTest.TestDefaultMultiSubnetFailoverorConnectionFailoverTests.TransientFault_IgnoreServerProvidedFailoverPartner_ShouldConnectToUserProvidedPartnerare setting these switches totrue.LocalAppContextSwitchesHelperhas its own way to deal with this - a staticSemaphoreSlimwhich only allows one writer at a time. I've chosen to use this in order to maintain consistency when dealing with AppContext switches.BatchTests.ParameterInOutAndReturnThis 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
StoredProcedureRAII primitive.AKVUnitTests,EnclaveAzureDatabaseTestsSurprisingly, 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.
SqlCommandCancelTestThis depended upon always catching a
SqlExceptionwhen an operation was cancelled. Sometimes this can be anInvalidOperationException.Issues
None.
Testing
Modified tests continue to pass.