Skip to content

Commit e8343ee

Browse files
authored
Fix race condition in Net.Security telemetry test (#56984)
1 parent 58efa4b commit e8343ee

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/libraries/System.Net.Security/tests/FunctionalTests/TelemetryTest.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ public static void EventSource_SuccessfulHandshake_LogsStartStop()
3636
listener.AddActivityTracking();
3737

3838
var events = new ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)>();
39-
await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), async () =>
39+
await listener.RunWithCallbackAsync(e =>
40+
{
41+
events.Enqueue((e, e.ActivityId));
42+
43+
if (e.EventName == "HandshakeStart")
44+
{
45+
// Wait for a new counter group so that current-tls-handshakes is guaranteed a non-zero value
46+
WaitForEventCountersAsync(events).GetAwaiter().GetResult();
47+
}
48+
},
49+
async () =>
4050
{
4151
// Invoke tests that'll cause some events to be generated
4252
var test = new SslStreamStreamToStreamTest_Async();
@@ -86,7 +96,17 @@ public static void EventSource_UnsuccessfulHandshake_LogsStartFailureStop()
8696
listener.AddActivityTracking();
8797

8898
var events = new ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)>();
89-
await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), async () =>
99+
await listener.RunWithCallbackAsync(e =>
100+
{
101+
events.Enqueue((e, e.ActivityId));
102+
103+
if (e.EventName == "HandshakeStart")
104+
{
105+
// Wait for a new counter group so that current-tls-handshakes is guaranteed a non-zero value
106+
WaitForEventCountersAsync(events).GetAwaiter().GetResult();
107+
}
108+
},
109+
async () =>
90110
{
91111
// Invoke tests that'll cause some events to be generated
92112
var test = new SslStreamStreamToStreamTest_Async();

0 commit comments

Comments
 (0)