From fca20b2b57f2842373628b3a6ddf3b3789c46c53 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Wed, 19 Jul 2023 18:22:07 +0200 Subject: [PATCH 1/2] Try to improve EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest reliability --- .../tests/FunctionalTests/TelemetryTest.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs index 82fac90c58f020..a6b5e659b912d6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs @@ -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); @@ -926,26 +924,31 @@ await Http11LoopbackServerFactory.Singleton.CreateClientAndServerAsync(async uri Task[] 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); } }); From 021916a2040e49e266d3297c011c9dc2da7f9122 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Wed, 19 Jul 2023 20:59:08 +0200 Subject: [PATCH 2/2] Bump the ListenBacklog --- .../System.Net.Http/tests/FunctionalTests/TelemetryTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs index a6b5e659b912d6..901ebd3ffb44fe 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs @@ -951,7 +951,8 @@ async Task HandleConnectionAsync(GenericLoopbackConnection connection) await connection.SendResponseAsync(HttpStatusCode.OK); } - }); + }, options: new GenericLoopbackOptions { ListenBacklog = NumParallelRequests }); + await WaitForEventCountersAsync(events); });