@@ -482,14 +482,18 @@ subtest stop_whole_process_group_gracefully => sub {
482482 # to check whether the sub processes would actually be granted
483483 # this number of seconds before getting killed. This is not set by
484484 # default to avoid slowing down the CI.
485- my $sub_process = Mojo::IOLoop::ReadWriteProcess-> new(
486- kill_sleeptime => 0.01,
487- sleeptime_during_kill => 0.01,
485+ my $interval = $ENV {MOJO_PROCESS_STOP_PGROUP_SLEEP_INTERVAL } // 0.01;
486+ my $timeout = $ENV {MOJO_PROCESS_STOP_PGROUP_TIMEOUT } // 15;
487+ my $kill_sleeptime = $ENV {TOTAL_SLEEPTIME_DURING_KILL } // ($interval * 5.0);
488+ my $patience = $timeout / $interval ;
489+ my $sub_process = Mojo::IOLoop::ReadWriteProcess-> new(
490+ kill_sleeptime => $interval ,
491+ sleeptime_during_kill => $interval ,
488492 max_kill_attempts => 1,
489493 separate_err => 0,
490494 blocking_stop => 1,
491495 kill_whole_group => 1,
492- total_sleeptime_during_kill => $ENV { TOTAL_SLEEPTIME_DURING_KILL } // 0.05 ,
496+ total_sleeptime_during_kill => $kill_sleeptime ,
493497 code => sub {
494498 $SIG {TERM } = ' IGNORE' ;
495499 setpgrp (0, 0);
@@ -503,13 +507,18 @@ subtest stop_whole_process_group_gracefully => sub {
503507 my $sub_process_pid = $sub_process -> pid;
504508 my $sub_process_gid ;
505509 note ' waiting until process group has been created' ;
506- sleep 0.01 while $test_gpid == ($sub_process_gid = getpgrp ($sub_process_pid ));
510+ sleep $interval
511+ while $test_gpid == ($sub_process_gid = getpgrp ($sub_process_pid ))
512+ && --$patience > 0;
507513 note " test pid: $$ , gpid: $test_gpid " ;
508514 note " sub process pid: $sub_process_pid , gpid: $sub_process_gid " ;
509515 note ' waiting until all sub processes have been forked' ;
510- sleep 0.01 until _number_of_process_in_group($sub_process_gid ) == 3;
516+ sleep $interval
517+ while _number_of_process_in_group($sub_process_gid ) != 3 && --$patience > 0;
511518
512519 $sub_process -> stop();
520+ note ' waiting until the process group is no longer running' ;
521+ sleep $interval while $sub_process -> is_running && --$patience > 0;
513522 is $sub_process -> is_running, 0, ' process is shut down via kill_whole_group' ;
514523};
515524
0 commit comments