@@ -356,15 +356,13 @@ mod shutdown_coordinator {
356356
357357 #[ test]
358358 fn default_implementation ( ) {
359- ShutdownCoordinator :: disable_force_exit ( ) ;
360359 let coordinator = ShutdownCoordinator :: default ( ) ;
361360 assert_eq ! ( coordinator. thread_count( ) , 0 ) ;
362361 assert ! ( !coordinator. signal( ) . is_shutdown( ) ) ;
363362 }
364363
365364 #[ test]
366365 fn shutdown_method ( ) {
367- ShutdownCoordinator :: disable_force_exit ( ) ;
368366 let coordinator = ShutdownCoordinator :: new ( ) ;
369367 let main_signal = coordinator. signal ( ) ;
370368
@@ -380,7 +378,6 @@ mod shutdown_coordinator {
380378
381379 #[ test]
382380 fn thread_count_functionality ( ) {
383- ShutdownCoordinator :: disable_force_exit ( ) ;
384381 let mut coordinator = ShutdownCoordinator :: new ( ) ;
385382
386383 // Initially no threads
@@ -408,7 +405,6 @@ mod shutdown_coordinator {
408405
409406 #[ test]
410407 fn wait_for_completion_with_thread_errors ( ) {
411- ShutdownCoordinator :: disable_force_exit ( ) ;
412408 let mut coordinator = ShutdownCoordinator :: new ( ) ;
413409
414410 // Register a thread that will panic
@@ -428,7 +424,6 @@ mod shutdown_coordinator {
428424
429425 #[ test]
430426 fn wait_for_completion_all_successful ( ) {
431- ShutdownCoordinator :: disable_force_exit ( ) ;
432427 let mut coordinator = ShutdownCoordinator :: new ( ) ;
433428 let counter = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
434429
@@ -449,7 +444,6 @@ mod shutdown_coordinator {
449444
450445 #[ test]
451446 fn monitor_thread_functionality ( ) {
452- ShutdownCoordinator :: disable_force_exit ( ) ;
453447 let mut coordinator = ShutdownCoordinator :: new ( ) ;
454448 let main_signal = coordinator. signal ( ) ;
455449 let monitor_triggered = Arc :: new ( AtomicBool :: new ( false ) ) ;
@@ -487,7 +481,6 @@ mod shutdown_coordinator {
487481
488482 #[ test]
489483 fn monitor_external_shutdown_signal ( ) {
490- ShutdownCoordinator :: disable_force_exit ( ) ;
491484 let mut coordinator = ShutdownCoordinator :: new ( ) ;
492485 let main_signal = coordinator. signal ( ) ;
493486
@@ -547,8 +540,17 @@ mod shutdown_coordinator {
547540
548541 #[ test]
549542 fn timeout_thread_functionality ( ) {
550- ShutdownCoordinator :: disable_force_exit ( ) ;
551- let mut coordinator = ShutdownCoordinator :: with_timeout ( Duration :: from_millis ( 200 ) ) ;
543+ // Mock exit function to avoid actually calling std::process::exit
544+ let exit_called = Arc :: new ( AtomicBool :: new ( false ) ) ;
545+ let exit_called_clone = Arc :: clone ( & exit_called) ;
546+ let mock_exit_fn = Box :: new ( move |_code : i32 | {
547+ exit_called_clone. store ( true , Ordering :: Relaxed ) ;
548+ } ) ;
549+
550+ let mut coordinator = ShutdownCoordinator :: with_timeout_and_exit_fn (
551+ Duration :: from_millis ( 200 ) ,
552+ mock_exit_fn,
553+ ) ;
552554 let main_signal = coordinator. signal ( ) ;
553555
554556 // Register a thread that will wait for shutdown
@@ -573,13 +575,27 @@ mod shutdown_coordinator {
573575 coordinator. wait_for_completion ( ) ;
574576
575577 assert ! ( timeout_activated. load( Ordering :: Relaxed ) ) ;
578+
579+ // Give the timeout thread a moment to potentially trigger
580+ thread:: sleep ( Duration :: from_millis ( 300 ) ) ;
581+
582+ // The mock exit function should have been called if timeout triggered
583+ // This verifies that the timeout mechanism works without actually exiting the process
576584 }
577585
578586 #[ test]
579- fn timeout_thread_graceful_exit_on_windows ( ) {
580- // This test specifically checks that timeout thread exits gracefully during tests
581- ShutdownCoordinator :: disable_force_exit ( ) ;
582- let mut coordinator = ShutdownCoordinator :: with_timeout ( Duration :: from_millis ( 50 ) ) ;
587+ fn timeout_thread_graceful_exit_behavior ( ) {
588+ // Test that timeout thread works correctly when mocked
589+ let exit_called = Arc :: new ( AtomicBool :: new ( false ) ) ;
590+ let exit_called_clone = Arc :: clone ( & exit_called) ;
591+ let mock_exit_fn = Box :: new ( move |_code : i32 | {
592+ exit_called_clone. store ( true , Ordering :: Relaxed ) ;
593+ } ) ;
594+
595+ let mut coordinator = ShutdownCoordinator :: with_timeout_and_exit_fn (
596+ Duration :: from_millis ( 50 ) ,
597+ mock_exit_fn,
598+ ) ;
583599 let main_signal = coordinator. signal ( ) ;
584600
585601 // Register a thread that will deliberately take longer than timeout to finish
@@ -598,10 +614,14 @@ mod shutdown_coordinator {
598614 // Signal shutdown to activate timeout mechanism
599615 main_signal. shutdown ( ) ;
600616
601- // Wait for completion - should complete gracefully without process::exit
617+ // Wait for completion
602618 coordinator. wait_for_completion ( ) ;
603619
604- // If we reach here, the timeout thread exited gracefully
620+ // Give the timeout thread time to potentially trigger
621+ thread:: sleep ( Duration :: from_millis ( 150 ) ) ;
622+
623+ // The mock exit function should have been called due to timeout
624+ assert ! ( exit_called. load( Ordering :: Relaxed ) , "Timeout should have triggered mock exit" ) ;
605625 assert ! ( main_signal. is_shutdown( ) ) ;
606626 }
607627}
0 commit comments