diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs index adfb0cbaeab9..5704640eb07d 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs @@ -1992,6 +1992,10 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP var readAsyncTask = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var requestAbortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + // Wait 2.5 seconds in debug (local development) and 15 seconds in production (CI) + // Use half the default timeout to ensure the host shuts down before the test throws an error while waiting. + var shutdownTimeout = Microsoft.AspNetCore.InternalTesting.TaskExtensions.DefaultTimeoutTimeSpan / 2; + var builder = CreateHostBuilder(async context => { context.RequestAborted.Register(() => requestAbortedTcs.SetResult()); @@ -2021,7 +2025,8 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP listenOptions.Protocols = protocol; listenOptions.UseHttps(TestResources.GetTestCertificate()); }); - }); + }, + shutdownTimeout: shutdownTimeout); using (var host = builder.Build()) using (var client = HttpHelpers.CreateClient()) @@ -2061,17 +2066,21 @@ await WaitForLogAsync(logs => }, "Check for initial GOAWAY frame sent on server initiated shutdown."); } + Logger.LogInformation("Getting read task"); var readTask = await readAsyncTask.Task.DefaultTimeout(); // Assert + Logger.LogInformation("Waiting for error from read task"); var ex = await Assert.ThrowsAnyAsync(() => readTask).DefaultTimeout(); - while (ex.InnerException != null) + + var rootException = ex; + while (rootException.InnerException != null) { - ex = ex.InnerException; + rootException = rootException.InnerException; } - Assert.IsType(ex); - Assert.Equal("The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout.", ex.Message); + Assert.IsType(rootException); + Assert.Equal("The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout.", rootException.Message); await requestAbortedTcs.Task.DefaultTimeout(); @@ -2191,8 +2200,8 @@ public async Task ServerReset_InvalidErrorCode() Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); } - private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action configureKestrel = null) + private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action configureKestrel = null, TimeSpan? shutdownTimeout = null) { - return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel); + return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel, shutdownTimeout: shutdownTimeout); } } diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/HttpHelpers.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/HttpHelpers.cs index 92bb131c4ed4..9621bb0cf768 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/HttpHelpers.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/HttpHelpers.cs @@ -63,7 +63,7 @@ public static HttpMessageInvoker CreateClient(TimeSpan? idleTimeout = null, Time return new HttpMessageInvoker(handler); } - public static IHostBuilder CreateHostBuilder(Action configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action configureKestrel = null, bool? plaintext = null) + public static IHostBuilder CreateHostBuilder(Action configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action configureKestrel = null, bool? plaintext = null, TimeSpan? shutdownTimeout = null) { return new HostBuilder() .ConfigureWebHost(webHostBuilder => @@ -102,7 +102,7 @@ public static IHostBuilder CreateHostBuilder(Action configur } else { - o.ShutdownTimeout = TimeSpan.FromSeconds(5); + o.ShutdownTimeout = shutdownTimeout ?? TimeSpan.FromSeconds(5); } }); }