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

Skip to content

Conversation

MichelZ
Copy link
Contributor

@MichelZ MichelZ commented Nov 20, 2024

AI Blurp

This pull request includes changes to the BatchTests.cs file to add retry logic for SQL commands and to enhance the SqlBatchCommand functionality. The most important changes are as follows:

Enhancements to SQL retry logic:

  • Added retry logic configuration using SqlRetryLogicOption and SqlRetryLogicBaseProvider to handle transient errors like deadlocks by retrying the operation up to three times with a delay of 100 milliseconds.

Improvements to SqlBatchCommand:

  • Modified StoredProcedureBatchSupported and MixedBatchSupported methods to include parameters in SqlBatchCommand for executing stored procedures, specifically adding a parameter for the sp_help stored procedure.

Additional imports:

  • Added System.Collections.Generic import to support the use of List<SqlParameter> in the updated methods.

Description

I regularly see deadlocks for the tests that use sp_help.
I'll try to mitigate this in 2 different ways:

  • Add a retry for ErrorNumber 1205 (Deadlock)
  • Add a parameter @objname that does less work so it's less likely to get a deadlock

It can probably also be solved by just using another stored procedure that's not prone to deadlocks, but I chose this way as the easiest path

Example test failure:
https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=101959&view=logs&j=700ebecb-e440-5400-66bb-488206e790af&t=d8ae6a68-b967-5b1e-ef3d-1b53d82075ee&l=826

Add parameter to sp_help
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.78%. Comparing base (b1f7eaf) to head (4ab317f).
Report is 85 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3025      +/-   ##
==========================================
+ Coverage   72.68%   72.78%   +0.09%     
==========================================
  Files         285      332      +47     
  Lines       59155    83162   +24007     
==========================================
+ Hits        42998    60530   +17532     
- Misses      16157    22632    +6475     
Flag Coverage Δ
addons 92.58% <ø> (ø)
netcore 74.50% <ø> (-0.89%) ⬇️
netfx 71.76% <ø> (+0.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichelZ MichelZ changed the title Fix SqlBatch Test Deadlocks Tests | Fix SqlBatch Test Deadlocks Nov 25, 2024
@mdaigle mdaigle added Code Health 💊 Issues/PRs that are targeted to source code quality improvements. Area\Tests Issues that are targeted to tests or test projects and removed Code Health 💊 Issues/PRs that are targeted to source code quality improvements. labels Nov 25, 2024
@paulmedynski
Copy link
Contributor

/azp run

@paulmedynski paulmedynski requested a review from a team March 20, 2025 18:48
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulmedynski paulmedynski self-assigned this Mar 21, 2025
@mdaigle mdaigle merged commit a78b086 into dotnet:main Mar 21, 2025
130 checks passed
@mdaigle mdaigle added this to the 7.0-preview1 milestone Mar 21, 2025
paulmedynski pushed a commit that referenced this pull request Sep 15, 2025
paulmedynski pushed a commit that referenced this pull request Sep 15, 2025
cheenamalhotra pushed a commit that referenced this pull request Sep 26, 2025
* User Story 38467: Backport mac server name fix

- Backported part of #3494 and all of #3591:
  - Added configurable test jobs timeout, defaulting to 90 minutes.
  - Reduced generated database names to 96 chars to try to fix macOS test failures.Increase test jobs timeout (#3591)

- Fixed the unique name generators to:
  - Keep max lengths to 30 and 96 characters respectively.
  - Ensure uniqueness at the start of the names.
  - Added link to database identifier syntax.

* User Story 38467: Backport mac server name fix

- Added a new test that was erroneously removed in the earlier cherry-pick.
- Added MDS_TEST_CONFIG environment variable to unit test config to override where the confi.json file is read from.
- Updated xUnit to 2.9.3 to avoid transitive System.Net.Http vulnerability warnings.

* Add retry on deadlock for sp_help (#3025)

Add parameter to sp_help

* User Story 38467: Backport mac server name fix

- Fixed cherry-pick of old function name.

* User Story 38467: Backport mac server name fix

- Removed macOS Azure SQL test configuration that uses service principal based auth that our Azure tenant no longer supports.

* User Story 38467: Backport mac server name fix

- Adding console diagnostics to slow enclave tests.

* User Story 38467: Backport mac server name fix

- Adding console diagnostics to slow enclave tests.

* User Story 38467: Backport mac server name fix

- Adding console diagnostics to slow enclave tests.

* Tests | Remove hardcoded credentials from ManualTests (#3204)

* Initial removal of CertificateUtility.CreateCertificate

One test implied that DataTestUtility.AKVUrl would point to an RSA key which aligned with the certificate's private key. Switching this to dynamically generate the key in places.

* Hotfix for Azure Key Vault tests

* Removed hardcoded references to Azure Key Vault key

* Removed hardcoded references to CertificateUtilityWin

These were mostly related to generating CSP keys.

* Code review changes

* Reorder properties and constructors
* Move AEConnectionStringProviderWithCspParameters to its own file
* Tweak to the AKV token acquisition

* Code review

Redundant bracket, alphabetised the ManualTesting csproj

* Update src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/SQLSetupStrategy.cs

Let's try @edwardneal's idea

Co-authored-by: Edward Neal <[email protected]>

* Update src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/SQLSetupStrategy.cs

Co-authored-by: Edward Neal <[email protected]>

* Fixes as per @edwardneal's suggestions

* Fix as per @edwardneal's suggestion

* Fix missing `new`

Co-authored-by: Edward Neal <[email protected]>

* Update src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/SQLSetupStrategyAzureKeyVault.cs

Co-authored-by: Edward Neal <[email protected]>

* Update src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/SQLSetupStrategyAzureKeyVault.cs

Co-authored-by: Edward Neal <[email protected]>

* Address comment that we don't need a CspParameters object as part of the test arguments
* Move test arguments into property (the class was only used in a single location)
* Cleanup test code
* Tweak default provider discovery code to handle edge cases a bit better

* Address comment regarding readonly member variables
Apply long line chomping

* Addressing the last of the comments.

---------

Co-authored-by: Edward Neal <[email protected]>

* - Fixed incorrect unique database object name function that doesn't compile normally.

* Updated TestUtilities project to target the same framework as the test project(s) it is compiling with.

* Removed diagnostic logging now that Enclave tests are passing.

---------

Co-authored-by: Michel Zehnder <[email protected]>
Co-authored-by: Benjamin Russell <[email protected]>
Co-authored-by: Edward Neal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area\Tests Issues that are targeted to tests or test projects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants