-
Notifications
You must be signed in to change notification settings - Fork 316
[6.1] Fix xevent test failures, avoid orphaned sessions #3817
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: release/6.1
Are you sure you want to change the base?
Conversation
- Added IsNotManagedInstance() for XEvents 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 pull request ports fixes from #3775 to the release/6.1 branch, addressing XEvent test failures and preventing orphaned XEvent sessions in test environments. The changes refactor the XEventScope test utility to include test names in session identifiers, add automatic session expiration for supported SQL Server versions, and convert affected test classes from static to instance-based to enable test name tracking.
Key changes:
- Refactored
XEventScopeto accept test name as first parameter and added MAX_DURATION support for Azure SQL and SQL Server 2025+ - Converted
XEventsTracingTestandDataStreamTestfrom static to instance-based classes withITestOutputHelperconstructors - Introduced
CurrentTestName()utility method using reflection to extract test names from xUnit's internal structures - Refactored
GetSqlServerProperty()to use aServerPropertyenum instead of string parameters
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/XEventsTracingTest.cs | Converted class to instance-based, added constructor with ITestOutputHelper, updated XEventScope usage to pass test name, added nullable annotations |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs | Converted class to instance-based, added constructor with ITestOutputHelper, updated XEventScope usage with test name and explicit connection opening, flattened using statements |
| src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs | Added CurrentTestName() method with regex parsing, added ServerProperty enum, refactored GetSqlServerProperty() to use enum, added IsNotManagedInstance() method, enhanced XEventScope with test name parameter, MAX_DURATION support, and improved documentation |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Show resolved
Hide resolved
| // Both Azure SQL and SQL Server 2025+ support setting a maximum | ||
| // duration for the XEvent session. |
Copilot
AI
Dec 1, 2025
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 comment states "Both Azure SQL and SQL Server 2025+ support setting a maximum duration" but the condition checks for version 17+, not specifically 2025+. While SQL Server 2025 is version 17, this could be confusing. Consider clarifying the comment:
// Both Azure SQL and SQL Server version 17 (SQL Server 2025) or higher
// support setting a maximum duration for the XEvent session.This makes it clear that version 17 corresponds to SQL Server 2025.
| // Both Azure SQL and SQL Server 2025+ support setting a maximum | |
| // duration for the XEvent session. | |
| // Both Azure SQL and SQL Server version 17 (SQL Server 2025) or higher | |
| // support setting a maximum duration for the XEvent session. |
| private static readonly Regex TestNameRegex = new( | ||
| // Capture the ClassName.MethodName portion, which may terminate | ||
| // the name, or have (args...) appended. | ||
| @"\.((?:[^.]+)\.(?:[^.\(]+))(?:\(.*\))?$", |
Copilot
AI
Dec 1, 2025
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 regex pattern @"\.((?:[^.]+)\.(?:[^.\(]+))(?:\(.*\))?$" uses a non-capturing group (?:[^.]+) for the class name and (?:[^.\(]+) for the method name, which is good. However, the pattern may not handle edge cases where:
- The test display name doesn't follow the expected format
- Class or method names contain escaped parentheses or other special characters
Consider adding more robust error handling around the regex matching logic, or documenting the assumptions about test name format more explicitly. The current assertions will cause the test to fail, but a more descriptive error message would help diagnose issues faster if xUnit changes its display name format.
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/6.1 #3817 +/- ##
================================================
+ Coverage 65.27% 90.82% +25.54%
================================================
Files 279 6 -273
Lines 61765 316 -61449
================================================
- Hits 40319 287 -40032
+ Misses 21446 29 -21417
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:
|
Description
Port of #3775 to release/6.1