Skip to content

Commit aa5cd2d

Browse files
committed
- Added XML docs for XEventSession test helper.
1 parent b895d7f commit aa5cd2d

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,19 +1319,27 @@ protected virtual void OnMatchingEventWritten(EventWrittenEventArgs eventData)
13191319

13201320
#region Properties
13211321

1322-
// The name of the XEvent session, derived from the session name
1323-
// provided at construction time, with a unique suffix appended.
1322+
/// <summary>
1323+
/// The name of the XEvent session, derived from the session name
1324+
/// provided at construction time, with a unique suffix appended.
1325+
/// </summary>
13241326
public string SessionName { get; }
13251327

13261328
#endregion
13271329

13281330
#region Construction
13291331

1330-
// Construct with the specified parameters.
1331-
//
1332-
// This will use the connection to query the server properties and
1333-
// setup and start the XEvent session.
1334-
//
1332+
/// <summary>
1333+
/// Construct with the specified parameters.
1334+
///
1335+
/// This will use the connection to query the server properties and
1336+
/// setup and start the XEvent session.
1337+
/// </summary>
1338+
/// <param name="sessionName">The base name of the session.</param>
1339+
/// <param name="connection">The SQL connection to use. (Must already be open.)</param>
1340+
/// <param name="eventSpecification">The event specification T-SQL string.</param>
1341+
/// <param name="targetSpecification">The target specification T-SQL string.</param>
1342+
/// <param name="durationInMinutes">The duration of the session in minutes.</param>
13351343
public XEventScope(
13361344
string sessionName,
13371345
// The connection must already be open.
@@ -1392,27 +1400,29 @@ public XEventScope(
13921400
createXEventSession.ExecuteNonQuery();
13931401
}
13941402

1395-
// Disposal stops and drops the XEvent session.
1396-
//
1397-
// Disposal isn't perfect - tests can abort without cleaning up the
1398-
// events they have created. For Azure SQL targets that outlive the
1399-
// test pipelines, it is beneficial to periodically log into the
1400-
// database and drop old XEvent sessions using T-SQL similar to
1401-
// this:
1402-
//
1403-
// DECLARE @sql NVARCHAR(MAX) = N'';
1404-
//
1405-
// -- Identify inactive (stopped) event sessions and generate DROP commands
1406-
// SELECT @sql += N'DROP EVENT SESSION [' + name + N'] ON SERVER;' + CHAR(13) + CHAR(10)
1407-
// FROM sys.server_event_sessions
1408-
// WHERE running = 0; -- Filter for sessions that are not running (inactive)
1409-
//
1410-
// -- Print the generated commands for review (optional, but recommended)
1411-
// PRINT @sql;
1412-
//
1413-
// -- Execute the generated commands
1414-
// EXEC sys.sp_executesql @sql;
1415-
//
1403+
/// <summary>
1404+
/// Disposal stops and drops the XEvent session.
1405+
/// </summary>
1406+
/// <remarks>
1407+
/// Disposal isn't perfect - tests can abort without cleaning up the
1408+
/// events they have created. For Azure SQL targets that outlive the
1409+
/// test pipelines, it is beneficial to periodically log into the
1410+
/// database and drop old XEvent sessions using T-SQL similar to
1411+
/// this:
1412+
///
1413+
/// DECLARE @sql NVARCHAR(MAX) = N'';
1414+
///
1415+
/// -- Identify inactive (stopped) event sessions and generate DROP commands
1416+
/// SELECT @sql += N'DROP EVENT SESSION [' + name + N'] ON SERVER;' + CHAR(13) + CHAR(10)
1417+
/// FROM sys.server_event_sessions
1418+
/// WHERE running = 0; -- Filter for sessions that are not running (inactive)
1419+
///
1420+
/// -- Print the generated commands for review (optional, but recommended)
1421+
/// PRINT @sql;
1422+
///
1423+
/// -- Execute the generated commands
1424+
/// EXEC sys.sp_executesql @sql;
1425+
/// </remarks>
14161426
public void Dispose()
14171427
{
14181428
string dropXEventSessionCommand = _isAzureSql
@@ -1431,8 +1441,13 @@ public void Dispose()
14311441

14321442
#region Public Methods
14331443

1434-
// Query the XEvent session for its collected events, returning them
1435-
// as an XML document.
1444+
/// <summary>
1445+
/// Query the XEvent session for its collected events, returning
1446+
/// them as an XML document.
1447+
///
1448+
/// This always blocks the thread for MaxDispatchLatencySeconds to
1449+
/// ensure that all events have been flushed into the ring buffer.
1450+
/// </summary>
14361451
public System.Xml.XmlDocument GetEvents()
14371452
{
14381453
string xEventQuery = _isAzureSql
@@ -1449,6 +1464,8 @@ INNER JOIN sys.dm_xe_sessions AS xe
14491464

14501465
using SqlCommand command = new SqlCommand(xEventQuery, _connection);
14511466

1467+
// Wait for maximum dispatch latency to ensure all events
1468+
// have been flushed to the ring buffer.
14521469
Thread.Sleep(MaxDispatchLatencySeconds * 1000);
14531470

14541471
string? targetData = command.ExecuteScalar() as string;

0 commit comments

Comments
 (0)