read_timeout.t: Skip the first test if STDIN isn't a tty or blocking

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-07-16 13:38:13 -03:00
parent fa5cbc8ca3
commit 4737995563
+25 -20
View File
@@ -20,27 +20,32 @@ use Time::HiRes qw(sleep time);
# ######################################################################### # #########################################################################
diag(`rm -rf /tmp/mqd.pid`); diag(`rm -rf /tmp/mqd.pid`);
my ($start, $end, $waited); my ($start, $end, $waited, $timeout);
my $timeout = wait_for( SKIP: {
sub { use IO::File;
$start = time; skip("Either not connected to a tty or STDIN isn't blocking, won't test"
`$trunk/bin/pt-query-digest --read-timeout 2 --pid /tmp/mqd.pid 2>/dev/null`; . " --read-timeout with STDIN", 1) if !-t STDIN || !STDIN->blocking();
return; $timeout = wait_for(
}, sub {
5, $start = time;
); `$trunk/bin/pt-query-digest --read-timeout 2 --pid /tmp/mqd.pid 2>/dev/null`;
$end = time; return;
$waited = $end - $start; },
if ( $timeout ) { 5,
# mqd ran longer than --read-timeout );
my $pid = `cat /tmp/mqd.pid`; $end = time;
`kill $pid`; $waited = $end - $start;
} if ( $timeout ) {
# mqd ran longer than --read-timeout
my $pid = `cat /tmp/mqd.pid`;
kill SIGTERM => $pid if $pid;
}
ok( ok(
$waited >= 2 && int($waited) < 4, $waited >= 2 && int($waited) < 4,
sprintf("--read-timeout 2 waited %.1f seconds reading STDIN", $waited) sprintf("--read-timeout 2 waited %.1f seconds reading STDIN", $waited)
); );
}
diag(`rm -rf /tmp/mqd.pid`); diag(`rm -rf /tmp/mqd.pid`);
diag(`rm -rf /tmp/mqd.fifo; mkfifo /tmp/mqd.fifo`); diag(`rm -rf /tmp/mqd.fifo; mkfifo /tmp/mqd.fifo`);