Tests | Introduce RAII SQL object primitives - #4050
Merged
mdaigle merged 9 commits intoApr 17, 2026
Merged
Conversation
This contains GenerateLongName and GenerateShortName, which are lifted from DataTestUtility.GetLongName and GetShortName in ManualTests.
This eliminates DropUserDefinedType from DataTestUtility.
Contributor
|
What does RAII mean exactly? |
Contributor
Author
|
Resource Acquisition Is Initialization - so we create SQL objects when a |
Member
|
/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 #4050 +/- ##
==========================================
- Coverage 74.62% 65.91% -8.72%
==========================================
Files 280 275 -5
Lines 43814 65805 +21991
==========================================
+ Hits 32698 43375 +10677
- Misses 11116 22430 +11314
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:
|
mdaigle
requested changes
Apr 16, 2026
mdaigle
approved these changes
Apr 17, 2026
6 tasks
paulmedynski
pushed a commit
that referenced
this pull request
May 7, 2026
* Create DatabaseObject base class for fixture This contains GenerateLongName and GenerateShortName, which are lifted from DataTestUtility.GetLongName and GetShortName in ManualTests. * Create derived types, use these in a few locations This eliminates DropUserDefinedType from DataTestUtility. * Further removal of ad-hoc utility methods in ParametersTest * Further removal of ad-hoc CREATE/DROP scripts in ParametersTest * Use Table type in SqlGraphTables.cs * Use Table and StoredProcedure types in JsonTest.cs * Use Table type in JsonStreamTest.cs * Remove duplicate helper function from ApiShould.cs
cheenamalhotra
added a commit
that referenced
this pull request
Aug 28, 2026
…ared Azure SQL DB (#4593) (#4594) Port of #4593 (main) adapted to release/7.0. TvpQueryHintsTests created its table type and stored procedure in the constructor and dropped them in Dispose, so the 5 tests in the class issued 20 DDL statements against the shared test database. On Azure SQL Database the resulting schema-modification lock contention pushed CREATE/DROP TYPE and CREATE/DROP PROCEDURE past the default 30 second command timeout, surfacing as sporadic 'Execution Timeout Expired' failures in the manual test legs. Create the type and procedure once per class via an IClassFixture (20 DDL statements -> 4) and raise the command timeout to 120s to absorb the contention that remains. The drop guards use TYPE_ID for the user-defined type and OBJECT_ID for the procedure. User-defined types live in sys.types rather than sys.objects, so OBJECT_ID never resolves them; using it there would silently skip the drop and leak the type into the shared database. Both lookups are parameterized. Note: release/7.0 does not contain the RAII UserDefinedType fixture from #4050, so the OBJECT_ID/TYPE_ID fix and the fixture parameterization changes in #4593 do not apply to this branch; only the DDL-volume fix is ported. Verified against SQL Server 2022: all 5 tests pass, zero orphaned QHint types or procedures remain, and the class runs ~2x faster (131ms -> 64ms) even without contention. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cfc64bc6-a9e6-490d-88b1-4b78d25aa103
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
This change is designed to make sure that the manual tests clean up after themselves and to introduce some consistency.
Many of the manual tests need to create objects - usually tables, stored procedures and UDTs. There are a handful of ways to do this. Some of the AlwaysEncrypted tests have a set of objects describing tables, column encryption keys, etc. The
DataTestUtilityclass hasCreateSP,DropSPand similar methods. Some tests have their own helper methods and others manually construct DDL statements. These are also used in various combinations, and most of the time the logic to delete these temporary objects is located in afinallyblock.Separately, the objects are created in different scopes - sometimes they're passed as fixtures to the test class, sometimes they're created by the constructor of a test class which implements
IDisposablebut most of the time they're created by each test.Lastly, the naming of these is sometimes odd. Sometimes the tests request a random object name, other times they'll use existing helper methods in
DataTestUtility, and other times still they'll attempt to use their own logic to generate a unique name.I'd like to simplify this with a consistent set of RAII-style types which represent database objects, returning its name post-hoc.
This PR starts the process by introducing types for a table, a UDT or an SP. It then applies these to a handful of tests (ApiShould, JsonStreamTest, JsonTest, SqlGraphTable, ParametersTest) to prove that they handle the edge cases. In a few cases (the two changed JsonStream tests) we eliminate test bugs which would always leave a JSON-based table behind, or which would leave files behind on the filesystem if an exception was thrown at the wrong time.
I expect it to take a while to migrate to the RAII types, but it should cut down on resource leaks in the Azure databases.
Issues
None.
Testing
Automated tests should continue to pass.