-
Notifications
You must be signed in to change notification settings - Fork 317
Tests | Msc Test Improvements/Cleanup #3842
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
…fail fast on any unexpected exception
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 improves test code maintainability and diagnostics by extracting the XEventScope class from DataTestUtility into its own file, rewriting test name extraction logic to be more robust, introducing helper extensions for SqlDataReader, and refactoring the AsyncCancelledConnectionsTest to use modern async/await patterns with better exception handling.
Key Changes:
- Extracted
XEventScopefromDataTestUtilityinto a standalone class with improved documentation and error handling (throws instead of asserts) - Rewrote
DataTestUtility.CurrentTestName()to traverse the xUnit object tree directly rather than parsingDisplayName, making it resilient to IDE test runner configuration differences - Converted
AsyncCancelledConnectionsTestfrom aFactwith internal loops to aTheorywithInlineData, implementing fail-fast exception handling instead of collecting exceptions
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
SqlDataReaderExtensions.cs |
New helper class with FlushAllResults and FlushResultSet extension methods for discarding data reader results |
XEventScope.cs |
Newly extracted class for managing XEvent sessions with improved XML docs, exception-based validation, and formatted SQL strings |
DataTestUtility.cs |
Removed XEventScope nested class and rewrote CurrentTestName to use object tree traversal instead of regex parsing |
AsyncCancelledConnectionsTest.cs |
Converted from Fact to Theory, refactored to use async/await properly, and implemented fail-fast exception handling with IsExpectedCancellation helper |
XEventsTracingTest.cs |
Updated to use standalone XEventScope class |
DataStreamTest.cs |
Updated to use standalone XEventScope class with target initializer syntax |
Microsoft.Data.SqlClient.ManualTesting.Tests.csproj |
Added reference to new XEventScope.cs file |
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/XEventScope.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/XEventScope.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/XEventScope.cs
Show resolved
Hide resolved
paulmedynski
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.
One question in the AsyncCancelledConnectionsTest.
| } | ||
|
|
||
| private void RunCancelAsyncConnections(SqlConnectionStringBuilder connectionStringBuilder) | ||
| private async Task RunCancelAsyncConnections(SqlConnectionStringBuilder connectionStringBuilder) |
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.
Now that you've made a single test theory, do we need a separate Run() function, or can this just be folded into the test body?
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.
Sure why not - but be careful what you wish for. This unlocked my cowboy coder and I decided to strip out all the tracking code in the test :)
…nc cancellation tests
| @@ -0,0 +1,204 @@ | |||
| using System; | |||
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.
missing license header
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.
Ok, I fixed it in all the files
mdaigle
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.
Accidentally clicked approve before
Description
As part of debugging some failing tests I've been working on, I tweaked some test code so I could more easily diagnose the issue. These changes aren't really worth mucking up the PRs I used them on, but I feel they are valuable enough to submit anyhow. Consider it a byproduct of other, more important work.
Here's a rundown of the changes:
SqlDataReaderExtensionclass that has some test-only extensions for commonly used behaviors that are just kinda ugly :)FlushAllResults- Reads and discards all results/sets from the provided data readerFlushResultSet- Reads and discards all results in the current set of the provided data readerDataTestUtilityfrom @paulmedynskiDisplayNameproperty of the currently runningITest- unfortunately this property can differently structured depending on the value ofmethodDisplay, which may be overridden by IDE test runners (ie, my IDE's test runner).AsyncCancelledConnectionTestfrom Fact that has two separate test runs inside it to aTheorywith inline data for enabling/disabling MARS.AsyncCancelledConnectionTestto no longer capture all exceptions and check for an empty collection of exceptions at the end, but instead let the exceptions bubble to the top to cause the test to fail faster and better expose the exception in test results. (this was implemented by codex 🤖)AsyncCancelledConnectionTestsuch that all the tracking/status displaying code is removed. The logging was pretty meaningless and added a lot of complexity to the code.Issues
N/A
Testing
Tests were ran locally and passed with their new changes. CI will validate.