Skip to content

Commit fa82d38

Browse files
committed
Account for MAX_DISPATCH_LATENCY in XEvents tests
XEvents are asynchronous, and are written to the target within MAX_DISPATCH_LATENCY seconds. We therefore need to wait that long before querying the target.
1 parent df35633 commit fa82d38

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,8 @@ protected virtual void OnMatchingEventWritten(EventWrittenEventArgs eventData)
10921092

10931093
public readonly ref struct XEventScope // : IDisposable
10941094
{
1095+
private const int MaxXEventsLatencyS = 5;
1096+
10951097
private readonly SqlConnection _connection;
10961098
private readonly bool _useDatabaseSession;
10971099

@@ -1126,6 +1128,8 @@ INNER JOIN sys.dm_xe_sessions AS xe
11261128

11271129
using (SqlCommand command = new SqlCommand(xEventQuery, _connection))
11281130
{
1131+
Thread.Sleep(MaxXEventsLatencyS * 1000);
1132+
11291133
if (_connection.State == ConnectionState.Closed)
11301134
{
11311135
_connection.Open();
@@ -1148,7 +1152,7 @@ private void SetupXEvent(string eventSpecification, string targetSpecification)
11481152
WITH (
11491153
MAX_MEMORY=4096 KB,
11501154
EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
1151-
MAX_DISPATCH_LATENCY=30 SECONDS,
1155+
MAX_DISPATCH_LATENCY={MaxXEventsLatencyS} SECONDS,
11521156
MAX_EVENT_SIZE=0 KB,
11531157
MEMORY_PARTITION_MODE=NONE,
11541158
TRACK_CAUSALITY=ON,

0 commit comments

Comments
 (0)