Re-enabled mock tests for H/3. (#53802)
authorMarie Píchová <11718369+ManickaP@users.noreply.github.com>
Fri, 11 Jun 2021 17:57:51 +0000 (19:57 +0200)
committerGitHub <noreply@github.com>
Fri, 11 Jun 2021 17:57:51 +0000 (19:57 +0200)
* Re-enabled mock tests for H/3.

* Used IsMockQuicSupported to run the mock tests only on supported platforms.

* Disabling mock test completely.

* Hanging test fix experiment.

* Disabled some mock tests failing in CI.

src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Mock/MockConnection.cs

index b56398b..76d80f2 100644 (file)
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit.Abstractions;
 using System.Net.Test.Common;
+using System.Net.Quic;
 
 namespace System.Net.Http.Functional.Tests
 {
@@ -30,6 +31,12 @@ namespace System.Net.Http.Functional.Tests
         [MemberData(nameof(AltSvcHeaderUpgradeVersions))]
         public async Task AltSvc_Header_Upgrade_Success(Version fromVersion, bool overrideHost)
         {
+            // [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
+            if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
+            {
+                return;
+            }
+
             // The test makes a request to a HTTP/1 or HTTP/2 server first, which supplies an Alt-Svc header pointing to the second server.
             using GenericLoopbackServer firstServer =
                 fromVersion.Major switch
@@ -73,6 +80,12 @@ namespace System.Net.Http.Functional.Tests
         [Fact]
         public async Task AltSvc_ConnectionFrame_UpgradeFrom20_Success()
         {
+            // [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
+            if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
+            {
+                return;
+            }
+
             using Http2LoopbackServer firstServer = Http2LoopbackServer.CreateServer();
             using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer();
             using HttpClient client = CreateHttpClient(HttpVersion.Version20);
@@ -98,6 +111,12 @@ namespace System.Net.Http.Functional.Tests
         [Fact]
         public async Task AltSvc_ResponseFrame_UpgradeFrom20_Success()
         {
+            // [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
+            if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
+            {
+                return;
+            }
+
             using Http2LoopbackServer firstServer = Http2LoopbackServer.CreateServer();
             using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer();
             using HttpClient client = CreateHttpClient(HttpVersion.Version20);
index 0a19368..6a41bfb 100644 (file)
@@ -170,7 +170,7 @@ namespace System.Net.Http.Functional.Tests
         {
             // This combination leads to a hang manifesting in CI only. Disabling it until there's more time to investigate.
             // [ActiveIssue("https://github.com/dotnet/runtime/issues/53688")]
-            if (streamLimit == 10 && this.UseQuicImplementationProvider == QuicImplementationProviders.Mock)
+            if (this.UseQuicImplementationProvider == QuicImplementationProviders.Mock)
             {
                 return;
             }
index 0ba14c6..81a4438 100644 (file)
@@ -31,6 +31,10 @@ namespace System.Net.Http.Functional.Tests
             }
         }
 
+        // This should correspond to platforms on which System.Net.Quic is supported. See also HttpConnectionPool.IsHttp3Supported().
+        public static bool IsMockQuicSupported
+            => (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();
+
         protected static HttpClientHandler CreateHttpClientHandler(Version useVersion = null, QuicImplementationProvider quicImplementationProvider = null, bool allowAllHttp2Certificates = true)
         {
             useVersion ??= HttpVersion.Version11;
index fb54f71..6d68042 100644 (file)
@@ -40,7 +40,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandler_HttpClientMiniStress_Http3_Mock : HttpClientMiniStress
     {
         public SocketsHttpHandler_HttpClientMiniStress_Http3_Mock(ITestOutputHelper output) : base(output) { }
index 6b7dbda..0ac38b2 100644 (file)
@@ -3083,7 +3083,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandlerTest_Http3_Mock : HttpClientHandlerTest_Http3
     {
         public SocketsHttpHandlerTest_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3098,7 +3098,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_Mock : HttpClientHandlerTest
     {
         public SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3117,7 +3117,7 @@ namespace System.Net.Http.Functional.Tests
     }
 
     [ActiveIssue("https://github.com/dotnet/runtime/issues/53093")]
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandlerTest_Cookies_Http3_Mock : HttpClientHandlerTest_Cookies
     {
         public SocketsHttpHandlerTest_Cookies_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3133,7 +3133,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_Mock : HttpClientHandlerTest_Headers
     {
         public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3152,7 +3152,7 @@ namespace System.Net.Http.Functional.Tests
     }
 
     [ActiveIssue("https://github.com/dotnet/runtime/issues/53093")]
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_Mock : SocketsHttpHandler_Cancellation_Test
     {
         public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3168,7 +3168,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_Mock : HttpClientHandler_AltSvc_Test
     {
         public SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_Mock(ITestOutputHelper output) : base(output) { }
@@ -3184,7 +3184,7 @@ namespace System.Net.Http.Functional.Tests
         protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
     }
 
-    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
+    [ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
     public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http3_Mock : HttpClientHandler_Finalization_Test
     {
         public SocketsHttpHandler_HttpClientHandler_Finalization_Http3_Mock(ITestOutputHelper output) : base(output) { }
index 3a876d2..3c1f232 100644 (file)
@@ -371,15 +371,20 @@ namespace System.Net.Quic.Implementations.Mock
 
             public void Decrement()
             {
+                TaskCompletionSource? availableTcs = null;
                 lock (_syncRoot)
                 {
                     --_actualCount;
                     if (!_availableTcs.Task.IsCompleted)
                     {
-                        _availableTcs.SetResult();
+                        availableTcs = _availableTcs;
                         _availableTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
                     }
                 }
+                if (availableTcs is not null)
+                {
+                    availableTcs.SetResult();
+                }
             }
 
             public bool TryIncrement()
@@ -396,7 +401,18 @@ namespace System.Net.Quic.Implementations.Mock
             }
 
             public ValueTask WaitForAvailableStreams(CancellationToken cancellationToken)
-                => new ValueTask(_availableTcs.Task.WaitAsync(cancellationToken));
+            {
+                TaskCompletionSource availableTcs;
+                lock (_syncRoot)
+                {
+                    if (_actualCount > 0)
+                    {
+                        return default;
+                    }
+                    availableTcs = _availableTcs;
+                }
+                return new ValueTask(availableTcs.Task.WaitAsync(cancellationToken));
+            }
 
             public void CloseWaiters()
                 => _availableTcs.SetException(ExceptionDispatchInfo.SetCurrentStackTrace(new QuicOperationAbortedException()));