-
Notifications
You must be signed in to change notification settings - Fork 3
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
Unit tests for Microsoft.Data.SqlClient.SqlClientEventSource #2
Unit tests for Microsoft.Data.SqlClient.SqlClientEventSource #2
Conversation
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionStringCommon.cs
Outdated
Show resolved
Hide resolved
Hi @winseros , The And according to the following comment, can we use reflection to access the counters directly instead of using EventListener? Thanks, |
Hi, @karinazhou The current implementation of the Lines 337 to 350 in 7ec5012
I see two options here:
What's your opinion? |
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Outdated
Show resolved
Hide resolved
@winseros Yes, you are right. To use reflections, this IsEnabled() condition needs to be removed. Otherwise, no points to use reflection if we need the EventListener to enable the events for counters. |
If we remove the |
After consultations with other teams, there are some perf benefits of removing the
|
@DavoudEshtehari OK. I will push the changes shortly. |
a89fcc5
to
0954f2d
Compare
cd05de4
to
59ebdb0
Compare
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Outdated
Show resolved
Hide resolved
@winseros I tested the unit tests locally but it failed at
It looks like a single run of either |
@karinazhou I still work on that. After we removed the Currently, I'm looking for tests that do leave open |
@winseros It sounds good. Please let me know if you need any help on this. I can look into this too. |
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs
Outdated
Show resolved
Hide resolved
Hi @winseros , Here are somethings needed to be updated before we can give this PR a final review:
One workaround is to compare the counters before and after SqlConnection.Open() or SqlConnection.Close(). The expected behavior will be to increase / decrease the counter by 1. This can eliminate the impact from other tests running before
Thanks, |
Hi, @karinazhou. The current status:
Regarding the dangling connections.When I started to work on tests, I tried to remember event counters' state before a test and check the changes after. The approach was working until I began to check the connection-pool related stuff. The connection pool counters appeared to be too unpredictable and depend on the pool state at the moment of the test. So the only way I see to get the So far, the I think at this moment I'll ask for @DavoudEshtehari `s help. I'm not sure how the internals should work, but I feel those two tests strike event counters out of balance.
@DavoudEshtehari could you please have a look and share your thoughts on those two? |
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariantTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariantTest.cs
Outdated
Show resolved
Hide resolved
That's right @winseros, we don't apply the GC effect on the connection pool because that would eliminate the benefits of having a pooler by causing another round trip to the server. Generally, to have more precise tests and avoid conflicts with other running tests, the following solutions would be useful:
Related links:PS: Default |
@DavoudEshtehari I'm not sure I found only two options that really work:
|
@winseros Could you explain more about the approach of studying the variation of counters values' problem by adding some samples you encountered with them to more examine before choosing other options? |
Hi, @DavoudEshtehari, sorry for answering with such a delay. I hope I understood the right way what you mean and giving a meaningful reply. Here is what I'm doing to reproduce the issue.
Please let me know if I can provide anything else that would help. |
@winseros Thank you for showing the issue in detail. I think what @DavoudEshtehari says is about why this method doesn't work in your case:
Since you have cleared the connection pools before running these three event counter test cases and the xunit runs the tests sequentially based on our setting, we are expecting the before-after check to reflect the changes correctly. Any reason we can't do it in this way? |
Hi @winseros, thank you for the answer.
|
@DavoudEshtehari I rewrote the tests as you pointed, and they started working! Thanks a lot! |
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs
Outdated
Show resolved
Hide resolved
Thank you @winseros, for the contribution. |
* Add event counters * Add support netstandard 2.1 & fix the conflict in event source * Support new event source types & add the test unit * Remove supporting obsolete types * fix unit test * Add snippet sample code * Address comments * Fix minor typo (#3) * Reformatting counter methods * Fix minor typo * Removed IsEnabled condition and reformatted counter methods * Unit tests for Microsoft.Data.SqlClient.SqlClientEventSource (#2) * Implemented tests for Microsoft.Data.SqlClient.SqlClientEventSource * Updated the EventCounter test to reflect the recent changes in the code * Working on EventCounter tests access event counters through reflection * Updated the EventCounterTest to use reflection * Fixing dangling SqlConnection's left in tests * EventCountersTest now checks hard/soft connects/disconnects counters * Reverted the DataTestUtility changes * Reverted using statements to the old-style in tests * Reverted the ConnectionPoolTest.ReclaimEmancipatedOnOpenTest() * Reverted using statements to the old-style in tests * Reverted using statements to the old-style in tests * Rewrite the EventCounterTest assertions not to conflict with other tests * Code review cleanup * Add more tests (#5) Added EventCounter_ReclaimedConnectionsCounter_Functional & EventCounter_ConnectionPoolGroupsCounter_Functional tests. * Address comments Co-authored-by: Davoud Eshtehari <[email protected]> Co-authored-by: Davoud Eshtehari <[email protected]> Co-authored-by: Karina Zhou <[email protected]> Co-authored-by: Nikita Kobzev <[email protected]>
Hi, @DavoudEshtehari. I added the tests that check the event-counters functionality. I managed to cover most of the counters.
Also, I changed the places where the
SqlClientEventSource.Log.ActiveConnectionPoolGroupRequest(false)
andSqlClientEventSource.Log.ActiveConnectionPoolGroupRequest(false)
calls are made, so the calls are invoked in a more "reusable" manner - closer to the place where the actual logic lives.As there are lots of tests running in the same session and lots of the tests does affect the event-counters when run, I had to call the
DbConnectionFactory.PruneConnectionPoolGroups()
andDbConnectionFactory.ClearAllPools()
before each test to get the underlying pooling infrastructure reset and tests reproducible. Those are internal methods, so I used reflection for that. But as an alternative, it could be done by allowing the[Microsoft.Data.SqlClient.ManualTesting.Tests]
assembly members to access the[Microsoft.Data.SqlClient]
internals.I'm looking forward to your feedback and suggestions.