Skip to content

Commit 783652d

Browse files
authored
Try to improve EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest reliability (#89192)
Closes #89035.
1 parent 1138b24 commit 783652d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,11 @@ public sealed class TelemetryTest_Http11 : TelemetryTest
902902
public TelemetryTest_Http11(ITestOutputHelper output) : base(output) { }
903903

904904
[OuterLoop]
905-
[ActiveIssue("https://github.com/dotnet/runtime/issues/89035", TestPlatforms.OSX)]
906905
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
907906
public void EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest()
908907
{
909908
RemoteExecutor.Invoke(async () =>
910909
{
911-
TimeSpan timeout = TimeSpan.FromSeconds(60);
912910
const int NumParallelRequests = 4;
913911

914912
using var listener = new TestEventListener("System.Net.Http", EventLevel.Verbose, eventCounterInterval: 0.1d);
@@ -926,29 +924,35 @@ await Http11LoopbackServerFactory.Singleton.CreateClientAndServerAsync(async uri
926924
Task<HttpResponseMessage>[] responseTasks = Enumerable.Repeat(uri, NumParallelRequests)
927925
.Select(_ => client.GetAsync(uri))
928926
.ToArray();
929-
await Task.WhenAll(responseTasks).WaitAsync(timeout);
930-
}, async server =>
927+
928+
await TestHelper.WhenAllCompletedOrAnyFailed(responseTasks);
929+
},
930+
async server =>
931931
{
932-
ManualResetEventSlim allConnectionsOpen = new(false);
932+
TaskCompletionSource allConnectionsOpen = new(TaskCreationOptions.RunContinuationsAsynchronously);
933933
int connectionCounter = 0;
934934

935935
Task[] parallelConnectionTasks = Enumerable.Repeat(server, NumParallelRequests)
936936
.Select(_ => server.AcceptConnectionAsync(HandleConnectionAsync))
937937
.ToArray();
938938

939-
await Task.WhenAll(parallelConnectionTasks);
939+
await TestHelper.WhenAllCompletedOrAnyFailed(parallelConnectionTasks);
940940

941941
async Task HandleConnectionAsync(GenericLoopbackConnection connection)
942942
{
943+
await connection.ReadRequestDataAsync().WaitAsync(TestHelper.PassingTestTimeout);
944+
943945
if (Interlocked.Increment(ref connectionCounter) == NumParallelRequests)
944946
{
945-
allConnectionsOpen.Set();
947+
allConnectionsOpen.SetResult();
946948
}
947-
await connection.ReadRequestDataAsync().WaitAsync(timeout);
948-
allConnectionsOpen.Wait(timeout);
949+
950+
await allConnectionsOpen.Task.WaitAsync(TestHelper.PassingTestTimeout);
951+
949952
await connection.SendResponseAsync(HttpStatusCode.OK);
950953
}
951-
});
954+
}, options: new GenericLoopbackOptions { ListenBacklog = NumParallelRequests });
955+
952956
await WaitForEventCountersAsync(events);
953957
});
954958

0 commit comments

Comments
 (0)