Mail-MtPolicyd
view release on metacpan or search on metacpan
t/step_definitions/00test-net-server_steps.pl view on Meta::CPAN
return $self->tmpdir.'/mtpolicyd.conf';
},
);
has 'pid_file' => ( is => 'ro', isa => 'Str', lazy => 1,
default => sub {
my $self = shift;
return( $self->tmpdir.'/pid');
}
);
has 'log_file' => ( is => 'ro', isa => 'Str', lazy => 1,
default => sub {
my $self = shift;
return( $self->tmpdir.'/log');
}
);
has 'port' => ( is => 'ro', isa => 'Int', lazy => 1,
default => sub {
# may work for now
return( 50000 + int(rand(10000)) );
},
);
sub pid {
my $self = shift;
if( ! -e $self->pid_file ) {
return;
}
my $file = IO::File->new( $self->pid_file, 'r');
if( ! defined $file ) {
die( 'could not open pid_file '.$self->pid_file.': '.$!);
}
my $pid = $file->getline;
chomp( $pid );
$file->close;
if( ! defined $pid ) {
return;
}
return( $pid );
}
has 'timeout' => ( is => 'ro', isa => 'Int', default => 10 );
sub wait_for_logfile {
my $self = shift;
my $retry = 0;
while( ! -e $self->log_file ) {
if( $retry >= $self->timeout ) {
die('timeout while waiting for log_file to appear!');
}
sleep(1);
$retry++;
}
return;
}
has 'lastlog' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
default => sub {[]},
);
sub wait_for_logmessage {
my $self = shift;
my $regex = shift;
my $log = IO::File->new( $self->log_file, 'r');
if( ! defined $log ) {
die('could not open logfile '.$self->log_file.': '.$!);
}
my $retry = 0;
for(;;) {
while( my $line = $log->getline ) {
chomp( $line );
push( @{$self->lastlog}, $line );
if( $line =~ /$regex/ ) {
return $line;
}
}
if( $retry >= $self->timeout ) {
die('timeout waiting for log message like '.$regex);
}
sleep(1);
$retry++;
}
return;
}
sub tail_log {
my $self = shift;
my @lines;
my $num_lines = 5;
if( @_ ) {
$num_lines = shift;
}
my $file = File::ReadBackwards->new( $self->log_file ) or
die "can't read 'log_file' $!" ;
while( @lines < $num_lines ) {
my $line = $file->getline;
if( ! defined $line ) {
last;
}
chomp( $line );
push( @lines, $line );
}
return( join("\n", reverse @lines) );
}
sub generate_config {
my $self = shift;
my $template = Template->new();
$template->process( $self->config_file, {
port => $self->port,
}, $self->tmp_config_file )
|| die "error processing config: ".$template->error(), "\n";
return;
}
( run in 2.928 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )