@@ -121,7 +121,6 @@ impl SlowHandlerState {
121121}
122122
123123#[ tokio:: test]
124- #[ cfg_attr( target_os = "windows" , ignore = "Flaky on Windows" ) ]
125124async fn graceful ( ) {
126125 let ( incoming, addr) = test_incoming ( ) . await ;
127126 let delay = Duration :: from_millis ( 100 ) ;
@@ -134,7 +133,11 @@ async fn graceful() {
134133
135134 let get_response = async move {
136135 let url = format ! ( "http://localhost:{}" , addr. port( ) ) ;
137- reqwest:: get ( url) . await . unwrap ( ) . error_for_status ( ) . unwrap ( ) ;
136+ reqwest:: get ( url)
137+ . await
138+ . unwrap ( )
139+ . error_for_status ( )
140+ . expect ( "The request failed" ) ;
138141 } ;
139142 let get_response = tokio:: task:: spawn ( get_response) ;
140143
@@ -145,15 +148,11 @@ async fn graceful() {
145148 let shutdown_future =
146149 tokio:: task:: spawn ( server_handle. shutdown ( ShutdownMode :: Graceful { timeout : delay * 5 } ) ) ;
147150
148- tokio:: select! {
149- v1 = get_response => {
150- // The request must succeed!
151- v1. unwrap( ) ;
152- } ,
153- _ = shutdown_future => {
154- panic!( "The server shutdown without waiting for an ongoing connection to complete within the allocated timeout" )
155- }
156- }
151+ shutdown_future
152+ . await
153+ . expect ( "Shutdown didn't succeed as expected" ) ;
154+
155+ get_response. await . expect ( "The server shutdown without waiting for an ongoing connection to complete within the allocated timeout" ) ;
157156}
158157
159158#[ tokio:: test]
@@ -179,20 +178,17 @@ async fn forced() {
179178 // Then start a forced shutdown.
180179 let shutdown_future = tokio:: task:: spawn ( server_handle. shutdown ( ShutdownMode :: Forced ) ) ;
181180
182- tokio:: select! {
183- outcome = get_response => {
184- // This future might resolve first and report a broken connection, which would be fine.
185- // We don't want to see it succeed!
186- if outcome. is_ok( ) {
187- panic!( "The server was supposed to shutdown forcefully, but it waited for the ongoing request" )
188- }
189- } ,
190- _ = shutdown_future => { }
191- }
181+ shutdown_future
182+ . await
183+ . expect ( "Shutdown didn't succeed as expected" ) ;
184+
185+ assert ! (
186+ get_response. await . unwrap_err( ) . is_panic( ) ,
187+ "The server was supposed to shutdown forcefully, but it waited for the ongoing request"
188+ ) ;
192189}
193190
194191#[ tokio:: test]
195- #[ cfg_attr( target_os = "windows" , ignore = "Flaky on Windows" ) ]
196192async fn graceful_but_too_fast ( ) {
197193 let ( incoming, addr) = test_incoming ( ) . await ;
198194 let delay = Duration :: from_millis ( 200 ) ;
@@ -217,14 +213,13 @@ async fn graceful_but_too_fast() {
217213 let shutdown_future =
218214 tokio:: task:: spawn ( server_handle. shutdown ( ShutdownMode :: Graceful { timeout : delay / 5 } ) ) ;
219215
220- tokio:: select! {
221- outcome = get_response => {
222- // This future might resolve first and report a broken connection, which would be fine.
223- // We don't want to see it succeed!
224- if outcome. is_ok( ) {
225- panic!( "The server was supposed to shutdown forcefully the slow request, but it waited instead" )
226- }
227- } ,
228- _ = shutdown_future => { }
229- }
216+ shutdown_future
217+ . await
218+ . expect ( "Shutdown didn't succeed as expected" ) ;
219+
220+ // The server should have shutdown gracefully, but the request should have failed.
221+ assert ! (
222+ get_response. await . unwrap_err( ) . is_panic( ) ,
223+ "The server was supposed to shutdown forcefully the slow request, but it waited instead"
224+ ) ;
230225}
0 commit comments