Skip to content

Commit

Permalink
Avoid test race condition between two completing requests (#52887)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed May 18, 2021
1 parent 7be77b8 commit 610f34e
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn
{
var firstRequestReceived = new SemaphoreSlim(0, 1);
var secondRequestSent = new SemaphoreSlim(0, 1);
var firstRequestFinished = new SemaphoreSlim(0, 1);
await GetFactoryForVersion(version).CreateClientAndServerAsync(
async uri =>
Expand All @@ -605,7 +606,13 @@ await GetFactoryForVersion(version).CreateClientAndServerAsync(
Task secondRequest = client.GetStringAsync(uri);
secondRequestSent.Release();
await new[] { firstRequest, secondRequest }.WhenAllOrAnyFailed();
// We are asserting that ActivityIds between Start/Stop pairs match below
// We wait for the first request to finish to ensure that RequestStop events
// are logged in the same order as RequestStarts
await firstRequest;
firstRequestFinished.Release();
await secondRequest;
},
async server =>
{
Expand Down Expand Up @@ -634,6 +641,7 @@ await GetFactoryForVersion(version).CreateClientAndServerAsync(
await connection.SendResponseAsync();
// Second request
Assert.True(await firstRequestFinished.WaitAsync(TimeSpan.FromSeconds(10)));
await connection.ReadRequestDataAsync(readBody: false);
await connection.SendResponseAsync();
};
Expand Down

0 comments on commit 610f34e

Please sign in to comment.