@@ -1992,6 +1992,10 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
19921992 var readAsyncTask = new TaskCompletionSource < Task > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
19931993 var requestAbortedTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
19941994
1995+ // Wait 2.5 seconds in debug (local development) and 15 seconds in production (CI)
1996+ // Use half the default timeout to ensure the host shuts down before the test throws an error while waiting.
1997+ var shutdownTimeout = Microsoft . AspNetCore . InternalTesting . TaskExtensions . DefaultTimeoutTimeSpan / 2 ;
1998+
19951999 var builder = CreateHostBuilder ( async context =>
19962000 {
19972001 context . RequestAborted . Register ( ( ) => requestAbortedTcs . SetResult ( ) ) ;
@@ -2021,7 +2025,8 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
20212025 listenOptions . Protocols = protocol ;
20222026 listenOptions . UseHttps ( TestResources . GetTestCertificate ( ) ) ;
20232027 } ) ;
2024- } ) ;
2028+ } ,
2029+ shutdownTimeout : shutdownTimeout ) ;
20252030
20262031 using ( var host = builder . Build ( ) )
20272032 using ( var client = HttpHelpers . CreateClient ( ) )
@@ -2061,17 +2066,21 @@ await WaitForLogAsync(logs =>
20612066 } , "Check for initial GOAWAY frame sent on server initiated shutdown." ) ;
20622067 }
20632068
2069+ Logger . LogInformation ( "Getting read task" ) ;
20642070 var readTask = await readAsyncTask . Task . DefaultTimeout ( ) ;
20652071
20662072 // Assert
2073+ Logger . LogInformation ( "Waiting for error from read task" ) ;
20672074 var ex = await Assert . ThrowsAnyAsync < Exception > ( ( ) => readTask ) . DefaultTimeout ( ) ;
2068- while ( ex . InnerException != null )
2075+
2076+ var rootException = ex ;
2077+ while ( rootException . InnerException != null )
20692078 {
2070- ex = ex . InnerException ;
2079+ rootException = rootException . InnerException ;
20712080 }
20722081
2073- Assert . IsType < ConnectionAbortedException > ( ex ) ;
2074- 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 ) ;
2082+ Assert . IsType < ConnectionAbortedException > ( rootException ) ;
2083+ 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 ) ;
20752084
20762085 await requestAbortedTcs . Task . DefaultTimeout ( ) ;
20772086
@@ -2191,8 +2200,8 @@ public async Task ServerReset_InvalidErrorCode()
21912200 Assert . Equal ( HttpStatusCode . InternalServerError , response . StatusCode ) ;
21922201 }
21932202
2194- private IHostBuilder CreateHostBuilder ( RequestDelegate requestDelegate , HttpProtocols ? protocol = null , Action < KestrelServerOptions > configureKestrel = null )
2203+ private IHostBuilder CreateHostBuilder ( RequestDelegate requestDelegate , HttpProtocols ? protocol = null , Action < KestrelServerOptions > configureKestrel = null , TimeSpan ? shutdownTimeout = null )
21952204 {
2196- return HttpHelpers . CreateHostBuilder ( AddTestLogging , requestDelegate , protocol , configureKestrel ) ;
2205+ return HttpHelpers . CreateHostBuilder ( AddTestLogging , requestDelegate , protocol , configureKestrel , shutdownTimeout : shutdownTimeout ) ;
21972206 }
21982207}
0 commit comments