mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Add hires timestamp to PTDEVDEBUG. Debug daemonize.pl. Make wait_until() defaults shorter.
This commit is contained in:
@@ -31,10 +31,10 @@ package PerconaTest;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0;
|
||||||
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Time::HiRes qw(sleep);
|
use Time::HiRes qw(sleep time);
|
||||||
use POSIX qw(signal_h);
|
use POSIX qw(signal_h);
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
$Data::Dumper::Indent = 1;
|
$Data::Dumper::Indent = 1;
|
||||||
@@ -220,14 +220,16 @@ sub parse_file {
|
|||||||
# Wait until code returns true.
|
# Wait until code returns true.
|
||||||
sub wait_until {
|
sub wait_until {
|
||||||
my ( $code, $t, $max_t ) = @_;
|
my ( $code, $t, $max_t ) = @_;
|
||||||
$t ||= .5;
|
$t ||= .25;
|
||||||
$max_t ||= 10;
|
$max_t ||= 5;
|
||||||
|
|
||||||
my $slept = 0;
|
my $slept = 0;
|
||||||
while ( $slept <= $max_t ) {
|
while ( $slept <= $max_t ) {
|
||||||
return 1 if $code->();
|
return 1 if $code->();
|
||||||
|
PTDEVDEBUG && _d('wait_until sleeping', $t);
|
||||||
sleep $t;
|
sleep $t;
|
||||||
$slept += $t;
|
$slept += $t;
|
||||||
|
PTDEVDEBUG && _d('wait_until slept', $slept, 'of', $max_t);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -622,7 +624,8 @@ sub _d {
|
|||||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||||
map { defined $_ ? $_ : 'undef' }
|
map { defined $_ ? $_ : 'undef' }
|
||||||
@_;
|
@_;
|
||||||
print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
|
my $t = sprintf '%.3f', time;
|
||||||
|
print STDERR "# $package:$line $PID $t ", join(' ', @_), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@@ -54,17 +54,19 @@ ok(! -f $pid_file, 'Removes PID file upon exit');
|
|||||||
# ############################################################################
|
# ############################################################################
|
||||||
rm_tmp_files();
|
rm_tmp_files();
|
||||||
|
|
||||||
system("$cmd 2 --daemonize --log $log_file");
|
system("$cmd 0 --daemonize --log $log_file");
|
||||||
PerconaTest::wait_for_files($log_file);
|
PerconaTest::wait_for_files($log_file);
|
||||||
ok(-f $log_file, 'Log file exists');
|
ok(-f $log_file, 'Log file exists');
|
||||||
|
|
||||||
sleep 2;
|
|
||||||
$output = `cat $log_file`;
|
$output = `cat $log_file`;
|
||||||
like($output, qr/STDOUT\nSTDERR\n/, 'STDOUT and STDERR went to log file');
|
like($output, qr/STDOUT\nSTDERR\n/, 'STDOUT and STDERR went to log file');
|
||||||
|
|
||||||
|
my $log_size = -s $log_file;
|
||||||
|
PTDEVDEBUG && PerconaTest::_d('log size', $log_size);
|
||||||
|
|
||||||
# Check that the log file is appended to.
|
# Check that the log file is appended to.
|
||||||
system("$cmd 0 --daemonize --log $log_file");
|
system("$cmd 0 --daemonize --log $log_file");
|
||||||
PerconaTest::wait_for_files($log_file);
|
PerconaTest::wait_until(sub { -s $log_file > $log_size });
|
||||||
$output = `cat $log_file`;
|
$output = `cat $log_file`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
@@ -82,7 +84,7 @@ ok(
|
|||||||
'PID file already exists'
|
'PID file already exists'
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = `PTDEBUG=1 $cmd 0 --daemonize --pid $pid_file 2>&1`;
|
$output = `$cmd 2 --daemonize --pid $pid_file 2>&1`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr{The PID file $pid_file already exists},
|
qr{The PID file $pid_file already exists},
|
||||||
@@ -126,6 +128,8 @@ SKIP: {
|
|||||||
$proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
|
$proc_fd_0 = -l "/proc/$pid/0" ? "/proc/$pid/0"
|
||||||
: -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
|
: -l "/proc/$pid/fd/0" ? "/proc/$pid/fd/0"
|
||||||
: die "Cannot find fd 0 symlink in /proc/$pid";
|
: die "Cannot find fd 0 symlink in /proc/$pid";
|
||||||
|
PTDEVDEBUG && PerconaTest::_d('pid_file', $pid_file,
|
||||||
|
'pid', $pid, 'proc_fd_0', $proc_fd_0, `ls -l $proc_fd_0`);
|
||||||
$stdin = readlink $proc_fd_0;
|
$stdin = readlink $proc_fd_0;
|
||||||
like(
|
like(
|
||||||
$stdin,
|
$stdin,
|
||||||
|
@@ -11,9 +11,10 @@ BEGIN {
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
|
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG};
|
use constant PTDEVDEBUG => $ENV{PTDEVDEBUG};
|
||||||
|
|
||||||
|
use Time::HiRes qw(sleep);
|
||||||
|
|
||||||
use Daemon;
|
use Daemon;
|
||||||
use OptionParser;
|
use OptionParser;
|
||||||
@@ -23,7 +24,8 @@ my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl");
|
|||||||
$o->get_specs();
|
$o->get_specs();
|
||||||
$o->get_opts();
|
$o->get_opts();
|
||||||
|
|
||||||
if ( scalar @ARGV < 1 ) {
|
my ($sleep_time) = shift @ARGV;
|
||||||
|
if ( !defined $sleep_time ) {
|
||||||
$o->save_error('No SLEEP_TIME specified');
|
$o->save_error('No SLEEP_TIME specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,15 +33,22 @@ $o->usage_or_errors();
|
|||||||
|
|
||||||
my $daemon;
|
my $daemon;
|
||||||
if ( $o->get('daemonize') ) {
|
if ( $o->get('daemonize') ) {
|
||||||
|
PTDEVDEBUG && PerconaTest::_d('daemonizing');
|
||||||
|
|
||||||
|
$OUTPUT_AUTOFLUSH = 1;
|
||||||
|
|
||||||
$daemon = new Daemon(o=>$o);
|
$daemon = new Daemon(o=>$o);
|
||||||
$daemon->daemonize();
|
$daemon->daemonize();
|
||||||
|
PTDEVDEBUG && PerconaTest::_d('daemonized');
|
||||||
|
|
||||||
print "STDOUT\n";
|
print "STDOUT\n";
|
||||||
print STDERR "STDERR\n";
|
print STDERR "STDERR\n";
|
||||||
|
|
||||||
sleep $ARGV[0];
|
PTDEVDEBUG && PerconaTest::_d('daemon sleep', $sleep_time);
|
||||||
|
sleep $sleep_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PTDEVDEBUG && PerconaTest::_d('daemon done');
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
@@ -50,7 +59,7 @@ exit;
|
|||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
Usage: daemonizes.pl SLEEP_TIME [ARGS]
|
Usage: daemonizes.pl SLEEP_TIME
|
||||||
|
|
||||||
daemonizes.pl daemonizes, prints to STDOUT and STDERR, sleeps and exits.
|
daemonizes.pl daemonizes, prints to STDOUT and STDERR, sleeps and exits.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user