Skip to content

Commit 610f34e

Browse files
authored
Avoid test race condition between two completing requests (#52887)
1 parent 7be77b8 commit 610f34e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn
585585
{
586586
var firstRequestReceived = new SemaphoreSlim(0, 1);
587587
var secondRequestSent = new SemaphoreSlim(0, 1);
588+
var firstRequestFinished = new SemaphoreSlim(0, 1);
588589

589590
await GetFactoryForVersion(version).CreateClientAndServerAsync(
590591
async uri =>
@@ -605,7 +606,13 @@ await GetFactoryForVersion(version).CreateClientAndServerAsync(
605606
Task secondRequest = client.GetStringAsync(uri);
606607
secondRequestSent.Release();
607608

608-
await new[] { firstRequest, secondRequest }.WhenAllOrAnyFailed();
609+
// We are asserting that ActivityIds between Start/Stop pairs match below
610+
// We wait for the first request to finish to ensure that RequestStop events
611+
// are logged in the same order as RequestStarts
612+
await firstRequest;
613+
firstRequestFinished.Release();
614+
615+
await secondRequest;
609616
},
610617
async server =>
611618
{
@@ -634,6 +641,7 @@ await GetFactoryForVersion(version).CreateClientAndServerAsync(
634641
await connection.SendResponseAsync();
635642

636643
// Second request
644+
Assert.True(await firstRequestFinished.WaitAsync(TimeSpan.FromSeconds(10)));
637645
await connection.ReadRequestDataAsync(readBody: false);
638646
await connection.SendResponseAsync();
639647
};

0 commit comments

Comments
 (0)