File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -467,6 +467,10 @@ subtest 'process code()' => sub {
467467 is $p -> read_all, ' ' , ' stdout is empty' ;
468468};
469469
470+ sub _number_of_process_in_group {
471+ scalar (split " \n " , qx{ pgrep -g @_ } or die " Unable to run pgrep: $! " );
472+ }
473+
470474subtest stop_whole_process_group_gracefully => sub {
471475 my $test_script = check_bin(" $FindBin::Bin /data/simple_fork.pl" );
472476
@@ -497,7 +501,13 @@ subtest stop_whole_process_group_gracefully => sub {
497501 # stop would also stop the test itself.
498502 my $test_gpid = getpgrp (0);
499503 my $sub_process_pid = $sub_process -> pid;
500- sleep 0.1 while $test_gpid == getpgrp ($sub_process_pid );
504+ my $sub_process_gid ;
505+ note ' waiting until process group has been created' ;
506+ sleep 0.01 while $test_gpid == ($sub_process_gid = getpgrp ($sub_process_pid ));
507+ note " test pid: $$ , gpid: $test_gpid " ;
508+ note " sub process pid: $sub_process_pid , gpid: $sub_process_gid " ;
509+ note ' waiting until all sub processes have been forked' ;
510+ sleep 0.01 until _number_of_process_in_group($sub_process_gid ) == 3;
501511
502512 $sub_process -> stop();
503513 is $sub_process -> is_running, 0, ' process is shut down via kill_whole_group' ;
You can’t perform that action at this time.
0 commit comments