mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 21:19:59 +00:00
read_timeout.t: Avoid shelling out, also laxer timing tests to avoid white smoke
This commit is contained in:
@@ -14,21 +14,26 @@ use Test::More tests => 2;
|
||||
use PerconaTest;
|
||||
|
||||
use Time::HiRes qw(sleep time);
|
||||
use POSIX qw(mkfifo);
|
||||
|
||||
# #########################################################################
|
||||
# Issue 226: Fix mk-query-digest signal handling
|
||||
# #########################################################################
|
||||
diag(`rm -rf /tmp/mqd.pid`);
|
||||
my $pid_file = '/tmp/mqd.pid';
|
||||
my $fifo = '/tmp/mqd.fifo';
|
||||
unlink $pid_file and diag("Unlinking existing $pid_file");
|
||||
unlink $fifo and diag("Unlinking existing $fifo");
|
||||
|
||||
my ($start, $end, $waited, $timeout);
|
||||
SKIP: {
|
||||
skip("Not connected to a tty won't test --read-timeout with STDIN", 1)
|
||||
if !-t STDIN;
|
||||
use IO::File;
|
||||
skip("Either not connected to a tty or STDIN isn't blocking, won't test"
|
||||
. " --read-timeout with STDIN", 1) if !-t STDIN || !STDIN->blocking();
|
||||
STDIN->blocking(1);
|
||||
$timeout = wait_for(
|
||||
sub {
|
||||
$start = time;
|
||||
`$trunk/bin/pt-query-digest --read-timeout 2 --pid /tmp/mqd.pid 2>/dev/null`;
|
||||
`$trunk/bin/pt-query-digest --read-timeout 2 --pid $pid_file 2>/dev/null`;
|
||||
return;
|
||||
},
|
||||
5,
|
||||
@@ -37,24 +42,24 @@ SKIP: {
|
||||
$waited = $end - $start;
|
||||
if ( $timeout ) {
|
||||
# mqd ran longer than --read-timeout
|
||||
my $pid = `cat /tmp/mqd.pid`;
|
||||
chomp(my $pid = slurp_file($pid_file));
|
||||
kill SIGTERM => $pid if $pid;
|
||||
}
|
||||
|
||||
ok(
|
||||
$waited >= 2 && int($waited) < 4,
|
||||
$waited >= 2 && int($waited) <= 4,
|
||||
sprintf("--read-timeout 2 waited %.1f seconds reading STDIN", $waited)
|
||||
);
|
||||
}
|
||||
|
||||
diag(`rm -rf /tmp/mqd.pid`);
|
||||
diag(`rm -rf /tmp/mqd.fifo; mkfifo /tmp/mqd.fifo`);
|
||||
system("$trunk/t/pt-query-digest/samples/write-to-fifo.pl /tmp/mqd.fifo 4 &");
|
||||
unlink $pid_file;
|
||||
mkfifo $fifo, 0700;
|
||||
system("$trunk/t/pt-query-digest/samples/write-to-fifo.pl $fifo 4 &");
|
||||
|
||||
$timeout = wait_for(
|
||||
sub {
|
||||
$start = time;
|
||||
`$trunk/bin/pt-query-digest --read-timeout 2 --pid /tmp/mqd.pid /tmp/mqd.fifo`;
|
||||
`$trunk/bin/pt-query-digest --read-timeout 2 --pid $pid_file $fifo`;
|
||||
return;
|
||||
},
|
||||
5,
|
||||
@@ -63,17 +68,17 @@ $end = time;
|
||||
$waited = $end - $start;
|
||||
if ( $timeout ) {
|
||||
# mqd ran longer than --read-timeout
|
||||
my $pid = `cat /tmp/mqd.pid`;
|
||||
`kill $pid`;
|
||||
chomp(my $pid = slurp_file($pid_file));
|
||||
kill SIGTERM => $pid if $pid;
|
||||
}
|
||||
|
||||
ok(
|
||||
$waited >= 2 && int($waited) < 4,
|
||||
$waited >= 2 && int($waited) <= 4,
|
||||
sprintf("--read-timeout waited %.1f seconds reading a file", $waited)
|
||||
);
|
||||
|
||||
diag(`rm -rf /tmp/mqd.pid`);
|
||||
diag(`rm -rf /tmp/mqd.fifo`);
|
||||
unlink $pid_file;
|
||||
unlink $fifo;
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
Reference in New Issue
Block a user