Merge lp:~percona-toolkit-dev/percona-toolkit/fix-test-suite-errors

This commit is contained in:
Daniel Nichter
2012-08-15 13:30:21 -06:00
4 changed files with 39 additions and 48 deletions

View File

@@ -1429,14 +1429,12 @@ my %modes = (
'ultra-raw' => 5, 'ultra-raw' => 5,
); );
{ {
my $fd_stdin = fileno(STDIN); my $fd_stdin = fileno(STDIN);
my $flags; my $flags;
unless ( $PerconaTest::DONT_RESTORE_STDIN ) { unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
$flags = fcntl(STDIN, F_GETFL, 0) $flags = fcntl(STDIN, F_GETFL, 0)
or warn "can't fcntl F_GETFL: $!"; or warn "Error getting STDIN flags with fcntl: $OS_ERROR";
} }
my $term = POSIX::Termios->new(); my $term = POSIX::Termios->new();
$term->getattr($fd_stdin); $term->getattr($fd_stdin);
@@ -1468,14 +1466,13 @@ my %modes = (
$term->setlflag($oterm); $term->setlflag($oterm);
$term->setcc( VTIME, 0 ); $term->setcc( VTIME, 0 );
$term->setattr( $fd_stdin, TCSANOW ); $term->setattr( $fd_stdin, TCSANOW );
unless ( $PerconaTest::DONT_RESTORE_STDIN ) { if ( !$PerconaTest::DONT_RESTORE_STDIN ) {
fcntl(STDIN, F_SETFL, $flags) fcntl(STDIN, F_SETFL, int($flags))
or warn "can't fcntl F_SETFL: $!"; or warn "Error restoring STDIN flags with fcntl: $OS_ERROR";
} }
} }
END { cooked() } END { cooked() }
} }
sub readkey { sub readkey {
@@ -1484,14 +1481,12 @@ sub readkey {
sysread(STDIN, $key, 1); sysread(STDIN, $key, 1);
my $timeout = 0.1; my $timeout = 0.1;
if ( $key eq "\033" ) { if ( $key eq "\033" ) {
{ my $x = '';
my $x = ''; STDIN->blocking(0);
STDIN->blocking(0); sysread(STDIN, $x, 2);
sysread(STDIN, $x, 2); STDIN->blocking(1);
STDIN->blocking(1); $key .= $x;
$key .= $x; redo if $key =~ /\[[0-2](?:[0-9];)?$/
redo if $key =~ /\[[0-2](?:[0-9];)?$/
}
} }
cooked(); cooked();
return $key; return $key;

View File

@@ -1,4 +1,4 @@
# This program is copyright 2010-2011 Percona Inc. # This program is copyright 2010-2012 Percona Inc.
# Feedback and improvements are welcome. # Feedback and improvements are welcome.
# #
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
@@ -66,14 +66,12 @@ my %modes = (
); );
# This primarily comes from the Perl Cookbook, recipe 15.8 # This primarily comes from the Perl Cookbook, recipe 15.8
{ {
my $fd_stdin = fileno(STDIN); my $fd_stdin = fileno(STDIN);
my $flags; my $flags;
unless ( $PerconaTest::DONT_RESTORE_STDIN ) { unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
$flags = fcntl(STDIN, F_GETFL, 0) $flags = fcntl(STDIN, F_GETFL, 0)
or warn "can't fcntl F_GETFL: $!"; or warn "Error getting STDIN flags with fcntl: $OS_ERROR";
} }
my $term = POSIX::Termios->new(); my $term = POSIX::Termios->new();
$term->getattr($fd_stdin); $term->getattr($fd_stdin);
@@ -105,14 +103,13 @@ my %modes = (
$term->setlflag($oterm); $term->setlflag($oterm);
$term->setcc( VTIME, 0 ); $term->setcc( VTIME, 0 );
$term->setattr( $fd_stdin, TCSANOW ); $term->setattr( $fd_stdin, TCSANOW );
unless ( $PerconaTest::DONT_RESTORE_STDIN ) { if ( !$PerconaTest::DONT_RESTORE_STDIN ) {
fcntl(STDIN, F_SETFL, $flags) fcntl(STDIN, F_SETFL, int($flags))
or warn "can't fcntl F_SETFL: $!"; or warn "Error restoring STDIN flags with fcntl: $OS_ERROR";
} }
} }
END { cooked() } END { cooked() }
} }
sub readkey { sub readkey {
@@ -121,17 +118,16 @@ sub readkey {
sysread(STDIN, $key, 1); sysread(STDIN, $key, 1);
my $timeout = 0.1; my $timeout = 0.1;
if ( $key eq "\033" ) { if ( $key eq "\033" ) {
# Ugly and broken hack, but good enough for the two minutes it took to write. # Ugly and broken hack, but good enough for the two minutes it took
# Namely, Ctrl escapes, the F-NUM keys, and other stuff you can send from the keyboard # to write. Namely, Ctrl escapes, the F-NUM keys, and other stuff
# take more than one "character" to represent, and would be wrong to break into pieces. # you can send from the keyboard take more than one "character" to
{ # represent, and would be wrong to break into pieces.
my $x = ''; my $x = '';
STDIN->blocking(0); STDIN->blocking(0);
sysread(STDIN, $x, 2); sysread(STDIN, $x, 2);
STDIN->blocking(1); STDIN->blocking(1);
$key .= $x; $key .= $x;
redo if $key =~ /\[[0-2](?:[0-9];)?$/ redo if $key =~ /\[[0-2](?:[0-9];)?$/
}
} }
cooked(); cooked();
return $key; return $key;

View File

@@ -9,13 +9,13 @@ 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 Test::More tests => 22; use Test::More;
use Time::HiRes qw(sleep); use Time::HiRes qw(sleep);
use File::Temp qw( tempfile ); use File::Temp qw( tempfile );
use Daemon; use Daemon;
use OptionParser; use OptionParser;
use PerconaTest; use PerconaTest;
#plan skip_all => "Hm";
use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0; use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0;
my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl"); my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl");
@@ -263,4 +263,5 @@ ok(
# Done. # Done.
# ############################################################################# # #############################################################################
rm_tmp_files(); rm_tmp_files();
done_testing;
exit; exit;

View File

@@ -9,15 +9,13 @@ 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 Test::More tests => 108; use Test::More;
use PerconaTest;
use OptionParser;
use File::Spec; use File::Spec;
use File::Temp (); use File::Temp ();
use PerconaTest;
use OptionParser;
BEGIN { BEGIN {
use_ok "Diskstats"; use_ok "Diskstats";
use_ok "DiskstatsGroupByAll"; use_ok "DiskstatsGroupByAll";
@@ -25,7 +23,7 @@ BEGIN {
use_ok "DiskstatsGroupBySample"; use_ok "DiskstatsGroupBySample";
} }
my $o = new OptionParser(description => 'Diskstats'); my $o = new OptionParser(description => 'Diskstats');
$o->get_specs("$trunk/bin/pt-diskstats"); $o->get_specs("$trunk/bin/pt-diskstats");
$o->get_opts(); $o->get_opts();
@@ -476,6 +474,7 @@ is_deeply(
$obj->clear_state(); $obj->clear_state();
} }
# ############################################################################ # ############################################################################
# The three subclasses # The three subclasses
# ############################################################################ # ############################################################################
@@ -491,7 +490,8 @@ for my $test (
{ {
class => "DiskstatsGroupBySample", class => "DiskstatsGroupBySample",
results_file_prefix => "sample", results_file_prefix => "sample",
}) { },
) {
my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1); my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1);
my $prefix = $test->{results_file_prefix}; my $prefix = $test->{results_file_prefix};
@@ -502,9 +502,8 @@ for my $test (
$obj->set_show_line_between_samples(0); $obj->set_show_line_between_samples(0);
for my $filename ( map "diskstats-00$_.txt", 1..5 ) { for my $filename ( map "diskstats-00$_.txt", 1..5 ) {
my $file = File::Spec->catfile( "t", "pt-diskstats", "samples", $filename ); my $file = File::Spec->catfile(qw(t pt-diskstats samples), $filename);
my $file_with_trunk = File::Spec->catfile( $trunk, $file ); my $file_with_trunk = File::Spec->catfile($trunk, $file);
my $expected = "t/pt-diskstats/expected/${prefix}_$filename"; my $expected = "t/pt-diskstats/expected/${prefix}_$filename";
ok( ok(
@@ -571,10 +570,10 @@ EOF
qr/Time between samples should be > 0, is /, qr/Time between samples should be > 0, is /,
"$test->{class}, ->_calc_deltas fails if the time elapsed is negative" "$test->{class}, ->_calc_deltas fails if the time elapsed is negative"
); );
} }
# ########################################################################### # ###########################################################################
# Done. # Done.
# ########################################################################### # ###########################################################################
done_testing;
exit; exit;