From fcb9bd46a4c8b0489501d48f0c41d594aa173644 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 13 Apr 2022 14:36:31 -0700 Subject: [PATCH 1/3] Fix flaky HTTP/2 test --- .../Http2/Http2ConnectionTests.cs | 3 +-- .../Http2/Http2KeepAliveTests.cs | 24 +++++++++---------- .../Http2/Http2StreamTests.cs | 2 +- .../Http2/Http2TestBase.cs | 6 ++++- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 55fafea7826e..6ddd8202f325 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -1879,7 +1879,7 @@ await InitializeConnectionAsync(async context => { requestAbortedTcs.SetException(ex); } - }).DefaultTimeout(); + }); await StartStreamAsync(1, _browserRequestHeaders, endStream: true).DefaultTimeout(); @@ -4725,7 +4725,6 @@ await ExpectAsync(Http2FrameType.DATA, } [Fact] - [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/41172")] public async Task AcceptNewStreamsDuringClosingConnection() { await InitializeConnectionAsync(_echoApplication); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2KeepAliveTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2KeepAliveTests.cs index 47d9ed74d51e..371a6f5f6f8d 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2KeepAliveTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2KeepAliveTests.cs @@ -13,7 +13,7 @@ public async Task KeepAlivePingDelay_InfiniteTimeSpan_KeepAliveNotEnabled() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = Timeout.InfiniteTimeSpan; - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); Assert.Null(_connection._keepAlive); @@ -26,7 +26,7 @@ public async Task KeepAlivePingTimeout_InfiniteTimeSpan_NoGoAway() _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingTimeout = Timeout.InfiniteTimeSpan; - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -56,7 +56,7 @@ public async Task IntervalExceeded_WithoutActivity_PingSent() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -79,7 +79,7 @@ public async Task IntervalExceeded_WithActivity_NoPingSent() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -103,7 +103,7 @@ public async Task IntervalNotExceeded_NoPingSent() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(5); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = new DateTimeOffset(1, TimeSpan.Zero); @@ -121,7 +121,7 @@ public async Task IntervalExceeded_MultipleTimes_PingsNotSentWhileAwaitingOnAck( { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -145,7 +145,7 @@ public async Task IntervalExceeded_MultipleTimes_PingSentAfterAck() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -185,7 +185,7 @@ public async Task TimeoutExceeded_NoAck_GoAway() _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingTimeout = TimeSpan.FromSeconds(3); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -217,7 +217,7 @@ public async Task TimeoutExceeded_NonPingActivity_NoGoAway() _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingTimeout = TimeSpan.FromSeconds(3); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -249,7 +249,7 @@ public async Task IntervalExceeded_StreamStarted_NoPingSent() { _serviceContext.ServerOptions.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(1); - await InitializeConnectionAsync(_noopApplication).DefaultTimeout(); + await InitializeConnectionAsync(_noopApplication); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -284,7 +284,7 @@ await InitializeConnectionAsync(async c => await tcs.Task; // Send headers await c.Request.Body.FlushAsync(); - }, expectedWindowUpdate: false).DefaultTimeout(); + }, expectedWindowUpdate: false); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; @@ -339,7 +339,7 @@ await InitializeConnectionAsync(async c => await tcs.Task; // Send headers await c.Request.Body.FlushAsync(); - }, expectedWindowUpdate: false).DefaultTimeout(); + }, expectedWindowUpdate: false); DateTimeOffset now = _serviceContext.MockSystemClock.UtcNow; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs index fdeb2f7d47cf..86ee7e2580a3 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs @@ -2562,7 +2562,7 @@ await InitializeConnectionAsync(async context => context.Response.BodyWriter.Advance(windowSize + 1); context.Response.AppendTrailer("CustomName", "Custom Value"); - }).DefaultTimeout(); + }); await StartStreamAsync(1, headers, endStream: true).DefaultTimeout(); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index b7d6b7a47535..9eed4623449d 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -10,6 +10,7 @@ using System.Net.Http; using System.Net.Http.HPack; using System.Reflection; +using System.Runtime.CompilerServices; using System.Text; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http; @@ -495,7 +496,10 @@ async Task CompletePipeOnTaskCompletion() _connectionTask = CompletePipeOnTaskCompletion(); } - protected async Task InitializeConnectionAsync(RequestDelegate application, int expectedSettingsCount = 3, bool expectedWindowUpdate = true) + protected ConfiguredTaskAwaitable InitializeConnectionAsync(RequestDelegate application, int expectedSettingsCount = 3, bool expectedWindowUpdate = true) => + InitializeConnectionAsyncCore(application, expectedSettingsCount, expectedWindowUpdate).ConfigureAwait(false); + + protected async Task InitializeConnectionAsyncCore(RequestDelegate application, int expectedSettingsCount, bool expectedWindowUpdate) { InitializeConnectionWithoutPreface(application); From bb16a3c6ab4f87a3d16c2ec9502b5a7405596178 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 13 Apr 2022 18:17:18 -0700 Subject: [PATCH 2/3] Keep test quarantined --- .../test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 6ddd8202f325..32db4a30432c 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -4725,6 +4725,7 @@ await ExpectAsync(Http2FrameType.DATA, } [Fact] + [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/41172")] public async Task AcceptNewStreamsDuringClosingConnection() { await InitializeConnectionAsync(_echoApplication); From 289d46a58948f15040ff882712f70f96d9159674 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 13 Apr 2022 18:21:32 -0700 Subject: [PATCH 3/3] private InnerInitializeConnectionAsync --- .../test/InMemory.FunctionalTests/Http2/Http2TestBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index 9eed4623449d..d9f6bec0a23b 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -497,9 +497,9 @@ async Task CompletePipeOnTaskCompletion() } protected ConfiguredTaskAwaitable InitializeConnectionAsync(RequestDelegate application, int expectedSettingsCount = 3, bool expectedWindowUpdate = true) => - InitializeConnectionAsyncCore(application, expectedSettingsCount, expectedWindowUpdate).ConfigureAwait(false); + InnerInitializeConnectionAsync(application, expectedSettingsCount, expectedWindowUpdate).ConfigureAwait(false); - protected async Task InitializeConnectionAsyncCore(RequestDelegate application, int expectedSettingsCount, bool expectedWindowUpdate) + private async Task InnerInitializeConnectionAsync(RequestDelegate application, int expectedSettingsCount, bool expectedWindowUpdate) { InitializeConnectionWithoutPreface(application);