@@ -1992,6 +1992,10 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
1992
1992
var readAsyncTask = new TaskCompletionSource < Task > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1993
1993
var requestAbortedTcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1994
1994
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
+
1995
1999
var builder = CreateHostBuilder ( async context =>
1996
2000
{
1997
2001
context . RequestAborted . Register ( ( ) => requestAbortedTcs . SetResult ( ) ) ;
@@ -2021,7 +2025,8 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
2021
2025
listenOptions . Protocols = protocol ;
2022
2026
listenOptions . UseHttps ( TestResources . GetTestCertificate ( ) ) ;
2023
2027
} ) ;
2024
- } ) ;
2028
+ } ,
2029
+ shutdownTimeout : shutdownTimeout ) ;
2025
2030
2026
2031
using ( var host = builder . Build ( ) )
2027
2032
using ( var client = HttpHelpers . CreateClient ( ) )
@@ -2061,17 +2066,21 @@ await WaitForLogAsync(logs =>
2061
2066
} , "Check for initial GOAWAY frame sent on server initiated shutdown." ) ;
2062
2067
}
2063
2068
2069
+ Logger . LogInformation ( "Getting read task" ) ;
2064
2070
var readTask = await readAsyncTask . Task . DefaultTimeout ( ) ;
2065
2071
2066
2072
// Assert
2073
+ Logger . LogInformation ( "Waiting for error from read task" ) ;
2067
2074
var ex = await Assert . ThrowsAnyAsync < Exception > ( ( ) => readTask ) . DefaultTimeout ( ) ;
2068
- while ( ex . InnerException != null )
2075
+
2076
+ var rootException = ex ;
2077
+ while ( rootException . InnerException != null )
2069
2078
{
2070
- ex = ex . InnerException ;
2079
+ rootException = rootException . InnerException ;
2071
2080
}
2072
2081
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 ) ;
2075
2084
2076
2085
await requestAbortedTcs . Task . DefaultTimeout ( ) ;
2077
2086
@@ -2191,8 +2200,8 @@ public async Task ServerReset_InvalidErrorCode()
2191
2200
Assert . Equal ( HttpStatusCode . InternalServerError , response . StatusCode ) ;
2192
2201
}
2193
2202
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 )
2195
2204
{
2196
- return HttpHelpers . CreateHostBuilder ( AddTestLogging , requestDelegate , protocol , configureKestrel ) ;
2205
+ return HttpHelpers . CreateHostBuilder ( AddTestLogging , requestDelegate , protocol , configureKestrel , shutdownTimeout : shutdownTimeout ) ;
2197
2206
}
2198
2207
}
0 commit comments