From 9ea8c200705e825f76be674676bfc6ac72f66dac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marie=20P=C3=ADchov=C3=A1?= <11718369+ManickaP@users.noreply.github.com> Date: Fri, 11 Jun 2021 19:57:51 +0200 Subject: [PATCH] Re-enabled mock tests for H/3. (#53802) * 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. --- .../FunctionalTests/HttpClientHandlerTest.AltSvc.cs | 19 +++++++++++++++++++ .../FunctionalTests/HttpClientHandlerTest.Http3.cs | 2 +- .../HttpClientHandlerTestBase.SocketsHttpHandler.cs | 4 ++++ .../FunctionalTests/HttpClientMiniStressTest.cs | 2 +- .../tests/FunctionalTests/SocketsHttpHandlerTest.cs | 14 +++++++------- .../Net/Quic/Implementations/Mock/MockConnection.cs | 20 ++++++++++++++++++-- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs index b56398b..76d80f2 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs @@ -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); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs index 0a19368..6a41bfb 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http3.cs @@ -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; } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs index 0ba14c6..81a4438 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs @@ -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; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs index fb54f71..6d68042 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs @@ -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) { } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs index 6b7dbda..0ac38b2 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs @@ -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) { } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Mock/MockConnection.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Mock/MockConnection.cs index 3a876d2..3c1f232 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Mock/MockConnection.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Mock/MockConnection.cs @@ -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())); -- 2.7.4