Skip to content

Commit

Permalink
Try to improve EventSource_ParallelRequests_LogsNewConnectionIdForEac…
Browse files Browse the repository at this point in the history
…hRequest reliability (#89192)

Closes #89035.
  • Loading branch information
MihaZupan authored Jul 27, 2023
1 parent 1138b24 commit 783652d
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,11 @@ public sealed class TelemetryTest_Http11 : TelemetryTest
public TelemetryTest_Http11(ITestOutputHelper output) : base(output) { }

[OuterLoop]
[ActiveIssue("https://github.com/dotnet/runtime/issues/89035", TestPlatforms.OSX)]
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest()
{
RemoteExecutor.Invoke(async () =>
{
TimeSpan timeout = TimeSpan.FromSeconds(60);
const int NumParallelRequests = 4;
using var listener = new TestEventListener("System.Net.Http", EventLevel.Verbose, eventCounterInterval: 0.1d);
Expand All @@ -926,29 +924,35 @@ await Http11LoopbackServerFactory.Singleton.CreateClientAndServerAsync(async uri
Task<HttpResponseMessage>[] responseTasks = Enumerable.Repeat(uri, NumParallelRequests)
.Select(_ => client.GetAsync(uri))
.ToArray();
await Task.WhenAll(responseTasks).WaitAsync(timeout);
}, async server =>
await TestHelper.WhenAllCompletedOrAnyFailed(responseTasks);
},
async server =>
{
ManualResetEventSlim allConnectionsOpen = new(false);
TaskCompletionSource allConnectionsOpen = new(TaskCreationOptions.RunContinuationsAsynchronously);
int connectionCounter = 0;
Task[] parallelConnectionTasks = Enumerable.Repeat(server, NumParallelRequests)
.Select(_ => server.AcceptConnectionAsync(HandleConnectionAsync))
.ToArray();
await Task.WhenAll(parallelConnectionTasks);
await TestHelper.WhenAllCompletedOrAnyFailed(parallelConnectionTasks);
async Task HandleConnectionAsync(GenericLoopbackConnection connection)
{
await connection.ReadRequestDataAsync().WaitAsync(TestHelper.PassingTestTimeout);
if (Interlocked.Increment(ref connectionCounter) == NumParallelRequests)
{
allConnectionsOpen.Set();
allConnectionsOpen.SetResult();
}
await connection.ReadRequestDataAsync().WaitAsync(timeout);
allConnectionsOpen.Wait(timeout);
await allConnectionsOpen.Task.WaitAsync(TestHelper.PassingTestTimeout);
await connection.SendResponseAsync(HttpStatusCode.OK);
}
});
}, options: new GenericLoopbackOptions { ListenBacklog = NumParallelRequests });
await WaitForEventCountersAsync(events);
});
Expand Down

0 comments on commit 783652d

Please sign in to comment.