For example:
package TTL::Test::Class;
use base qw(Test::Class);
use Test::More;
use POSIX ":sys_wait_h";
use constant DEFAULT_TIMEOUT => 60;
# переопределяем метод запуска тестов
sub runtests{
my $t = DEFAULT_TIMEOUT;
my $pid = fork;
my $child_ret_code;
if( $pid > 0 ){ # parent process
#child waiting loop
my $ok_flag = 0;
for(my $i=0; $i < $t; $i++){
if(waitpid($pid, WNOHANG)){
$child_ret_code = $?/256;
ok($child_ret_code);
$ok_flag = 1;
last;
};
sleep(1);
};
if( not $ok_flag ){
diag "Killing test by its timetolive...";
kill TERM =>
$pid;
return $ok_flag;
};
return $child_ret_code;
} elsif( $pid == 0 ) { #child
exit $self->SUPER::runtests;
} elsif ( not defined($pid) ) { #unsuccessfull fork
die "Cannot fork child process: $!";
}
}
1;
I think, we don't need SIGCHILD here..
source
Комментариев нет:
Отправить комментарий
Если Вы нашли ошибку у автора, у Вас есть вопрос или просто хотите поделиться чем-то полезным, то пишите - не стесняйтесь..