[release/8.0] Fix Dispose and SendData Race on Http3 Test (#91690)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Mon, 11 Sep 2023 23:17:44 +0000 (17:17 -0600)
committerGitHub <noreply@github.com>
Mon, 11 Sep 2023 23:17:44 +0000 (17:17 -0600)
* Fix Dispose and Send Data Race

* Review feedback

---------

Co-authored-by: Ahmet Ibrahim Aksoy (from Dev Box) <aaksoy@microsoft.com>
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs

index 92c4ab0..844d286 100644 (file)
@@ -1626,6 +1626,7 @@ namespace System.Net.Http.Functional.Tests
         public async Task ServerSendsTrailingHeaders_Success()
         {
             using Http3LoopbackServer server = CreateHttp3LoopbackServer();
+            SemaphoreSlim clientFinishedSemaphore = new SemaphoreSlim(0);
 
             Task serverTask = Task.Run(async () =>
             {
@@ -1636,6 +1637,7 @@ namespace System.Net.Http.Functional.Tests
                 await requestStream.ReadRequestDataAsync();
                 await requestStream.SendResponseAsync(isFinal: false);
                 await requestStream.SendResponseHeadersAsync(null, new[] { new HttpHeaderData("MyHeader", "MyValue") });
+                await clientFinishedSemaphore.WaitAsync(TimeSpan.FromSeconds(20));
             });
 
             Task clientTask = Task.Run(async () =>
@@ -1655,6 +1657,7 @@ namespace System.Net.Http.Functional.Tests
                 (string key, IEnumerable<string> value) = Assert.Single(response.TrailingHeaders);
                 Assert.Equal("MyHeader", key);
                 Assert.Equal("MyValue", Assert.Single(value));
+                clientFinishedSemaphore.Release();
             });
 
             await new[] { clientTask, serverTask }.WhenAllOrAnyFailed(200_000);