Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e17fe35

Browse files
authored
Add logging to sporadically failing ExecutionContext flow test (#28484)
1 parent db5fb33 commit e17fe35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/System.Net.Sockets/tests/FunctionalTests/ExecutionContextFlowTest.netcoreapp.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.IO;
66
using System.Runtime.CompilerServices;
7+
using System.Text;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using Xunit;
@@ -26,8 +27,13 @@ public Task ExecutionContext_FlowsOnlyOnceAcrossAsyncOperations()
2627
client.Connect(listener.LocalEndPoint);
2728
using (Socket server = listener.Accept())
2829
{
30+
var stackLog = new StringBuilder();
2931
int executionContextChanges = 0;
30-
var asyncLocal = new AsyncLocal<int>(_ => executionContextChanges++);
32+
var asyncLocal = new AsyncLocal<int>(_ =>
33+
{
34+
executionContextChanges++;
35+
stackLog.AppendLine($"#{executionContextChanges}: {Environment.StackTrace}");
36+
});
3137
Assert.Equal(0, executionContextChanges);
3238

3339
int numAwaits = 20;
@@ -44,7 +50,14 @@ public Task ExecutionContext_FlowsOnlyOnceAcrossAsyncOperations()
4450

4551
// This doesn't count EC changes where EC.Run is passed the same context
4652
// as is current, but it's the best we can track via public API.
47-
Assert.InRange(executionContextChanges, 1, numAwaits * 3); // at most: 1 / AsyncLocal change + 1 / suspend + 1 / resume
53+
try
54+
{
55+
Assert.InRange(executionContextChanges, 1, numAwaits * 3); // at most: 1 / AsyncLocal change + 1 / suspend + 1 / resume
56+
}
57+
catch (Exception e)
58+
{
59+
throw new Exception($"{nameof(executionContextChanges)} == {executionContextChanges} with log: {stackLog.ToString()}", e);
60+
}
4861
}
4962
}
5063
});

0 commit comments

Comments
 (0)