Skip to content

Commit 65f1c6b

Browse files
authored
Merge pull request #66 from Martchus/fix-tests
Fix sporadic failures in `t/01_run.t`
2 parents a0468f5 + 3ba588d commit 65f1c6b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

t/01_run.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
470474
subtest 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';

0 commit comments

Comments
 (0)