-
Notifications
You must be signed in to change notification settings - Fork 317
Connection pool transaction stress tests #3805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ransacted-pool-stress-tests
There was a problem hiding this 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 adds comprehensive stress tests for connection pool transaction handling under high concurrency scenarios. The tests verify that the WaitHandleDbConnectionPool and TransactedConnectionPool correctly manage connections when multiple threads perform transactional operations concurrently. Additionally, the PR removes several transitive package references for vulnerable dependencies that are no longer needed.
Key Changes
- Added
WaitHandleDbConnectionPoolTransactionStressTest.cswith extensive transaction stress tests covering various concurrency patterns - Exposed internal properties in
WaitHandleDbConnectionPoolandTransactedConnectionPoolfor test observability - Removed explicit references to
System.Formats.Asn1,System.Text.Json, andSystem.Text.Encodings.Webpackages (transitive dependencies)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
WaitHandleDbConnectionPoolTransactionStressTest.cs |
New comprehensive test file with 1125 lines covering transaction stress scenarios including per-iteration transactions, per-thread transactions, shared transactions, pool saturation, nested transactions, mixed transacted/non-transacted operations, and edge cases |
WaitHandleDbConnectionPool.cs |
Changed MaxPoolSize and MinPoolSize from private to internal, and exposed TransactedConnectionPool property as internal for test observability |
TransactedConnectionPool.cs |
Changed TransactedConnectionList to internal and replaced private _transactedCxns dictionary with internal TransactedConnections property for test access |
Microsoft.Data.SqlClient.ExtUtilities.csproj |
Removed explicit reference to System.Formats.Asn1 package |
netcore/src/Microsoft.Data.SqlClient.csproj |
Removed explicit reference to System.Text.Json package |
netcore/ref/Microsoft.Data.SqlClient.csproj |
Removed explicit reference to System.Text.Json package |
AzureKeyVaultProvider.csproj |
Removed explicit reference to System.Text.Encodings.Web package |
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 8 out of 8 changed files in this pull request and generated 5 comments.
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
....SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolTransactionStressTest.cs
Outdated
Show resolved
Hide resolved
benrr101
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The big problem here is adding stress tests to the unit test project. I can't approve that without some discussion on it.
| <PackageReference Include="System.Security.Cryptography.Pkcs" /> | ||
|
|
||
| <!-- Transitive dependencies that would otherwise bring in older, vulnerable versions. --> | ||
| <PackageReference Include="System.Text.Json" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want our ref packages to have the same references as the implementation packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean these up as part of DRI this sprint. Had to include them here to get some build errors addressed.
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Core" /> | ||
| <PackageReference Include="System.Text.Encodings.Web" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this related to adding stress tests for the connection pool?
| /// These tests verify that pool metrics remain consistent when connections are rapidly opened and closed | ||
| /// with intermingled transactions in a highly concurrent environment. | ||
| /// </summary> | ||
| public class WaitHandleDbConnectionPoolTransactionStressTest : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really really really hesitant to approve putting stress tests into the unit test project. Our goal here should be to have unit tests be atomic tests of units of code that can be mocked and stubbed to coerce certain desired behaviors. Stress tests don't fit that bill, since they often are dependent on unexpected behaviors outside the scope of the code itself (system load, primarily).
We've sort of boxed ourselves into a corner here. The test TDS server is way too large to really be considered "unit testing". The code itself isn't structured for proper unit testing. And the stress test project isn't really ready for things to be moved into it.
I'd really like it if we address this from a different angle. Either move it into the stress test project (and I can help with that since I've still got the stress test project plans in my head a bit), or come up with a way to get the fake TDS server tests/code out of (or isolated within) the unit test project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but these tests don't use the test TDS server, they use mocked connections.
| /// <value>The IDbConnectionPool instance that owns this transacted pool.</value> | ||
| internal IDbConnectionPool Pool { get; } | ||
|
|
||
| internal Dictionary<Transaction, TransactedConnectionList> TransactedConnections { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need private set here.
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Core" /> | ||
| <PackageReference Include="System.Text.Encodings.Web" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the scoop with these package removals? Have the transitive problems been solved somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean these up. Visual studio was complaining, so I did this to appease it. I think it was just holding on to stale partial build state.
| Task.WaitAll(tasks); | ||
|
|
||
| // Assert | ||
| AssertPoolMetrics(_pool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you be checking that the min/max are never exceeded at each iteration? This will just check that the pool currently hasn't exceeded those thresholds, not that it never did.
| { | ||
| var owner = new SqlConnection(); | ||
| _pool.TryGetConnection(owner, null, new DbConnectionOptions("", null), out var conn); | ||
| Assert.NotNull(conn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to confirm that this conn is enlisted with transaction?
| { | ||
| tasks[t] = Task.Run(() => | ||
| { | ||
| using (var innerScope = new TransactionScope(transaction)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect does innerScope have here? Should conn be associated to the inner scope, the outer scope, something else?
| } | ||
|
|
||
| // Shutdown pool while operations are in progress | ||
| _pool.Shutdown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we certain there are operations in progress here? It's possible all tasks have run to completion already.
Description
The flow of transacting connections through the connection pool is tested by manual tests, but these lack coverage of more intricate scenarios:
This PR adds the missing test coverage. Also includes minor refactors to improve test visibility of properties and types.
Issues
#3356
Testing
Described above.