@@ -311,17 +311,23 @@ mod tests {
311311 }
312312
313313 #[ tokio:: test]
314- #[ ignore]
315- // related https://github.com/apache/arrow-datafusion/issues/2140
316314 async fn executor_shutdown_while_task_running ( ) {
317- let barrier = Arc :: new ( Barrier :: new ( 2 ) ) ;
315+ let barrier_task_completed = Arc :: new ( Barrier :: new ( 2 ) ) ;
316+ // prevents executor shutdown before task gets running
317+ // otherwise there is race on task spawn and shutdown
318+ // leading barrier_task_completed waiting forever
319+ let barrier_task_running = Arc :: new ( Barrier :: new ( 2 ) ) ;
318320
319321 let exec = DedicatedExecutor :: new ( "Test DedicatedExecutor" , 1 ) ;
320- let dedicated_task = exec. spawn ( do_work ( 42 , Arc :: clone ( & barrier) ) ) ;
321-
322+ let dedicated_task = exec. spawn ( signal_running_do_work (
323+ 42 ,
324+ Arc :: clone ( & barrier_task_running) ,
325+ Arc :: clone ( & barrier_task_completed) ,
326+ ) ) ;
327+ barrier_task_running. wait ( ) ;
322328 exec. shutdown ( ) ;
323329 // block main thread until completion of the outstanding task
324- barrier . wait ( ) ;
330+ barrier_task_completed . wait ( ) ;
325331
326332 // task should complete successfully
327333 assert_eq ! ( dedicated_task. await . unwrap( ) , 42 ) ;
@@ -375,4 +381,15 @@ mod tests {
375381 barrier. wait ( ) ;
376382 result
377383 }
384+ /// signals when task starts running,
385+ /// waits on barrier and then returns result
386+ async fn signal_running_do_work (
387+ result : usize ,
388+ barrier_task_running : Arc < Barrier > ,
389+ barrier_task_finished : Arc < Barrier > ,
390+ ) -> usize {
391+ barrier_task_running. wait ( ) ;
392+ barrier_task_finished. wait ( ) ;
393+ result
394+ }
378395}
0 commit comments