Several fixes. --save-samples and --help should work now.

This commit is contained in:
Brian Fraser
2012-01-10 10:47:50 -03:00
parent 93271379d8
commit b4289010b1
10 changed files with 226 additions and 124 deletions

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More qw( no_plan );
use Test::More tests => 128;
use PerconaTest;
@@ -39,8 +39,9 @@ can_ok( $obj, qw(
) );
# Test the constructor
use File::Temp ();
for my $attr (
[ filename => '/corp/diskstats' ],
[ filename => (File::Temp::tempfile($0.'diskstats.XXXXXX', OPEN=>0, UNLINK=>1))[1]],
[ column_regex => qr/!!!/ ],
[ device_regex => qr/!!!/ ],
[ block_size => 215 ],
@@ -89,35 +90,31 @@ my %expected_results = (
);
# Copypasted from Diskstats.pm. If the one in there changes so should this.
my @columns_in_order = (
# Colum # Format # Key name
[ " rd_s" => "%7.1f", "reads_sec", ],
[ "rd_avkb" => "%7.1f", "avg_read_sz", ],
[ "rd_mb_s" => "%7.1f", "mbytes_read_sec", ],
[ "rd_mrg" => "%5.0f%%", "read_merge_pct", ],
[ "rd_cnc" => "%6.1f", "read_conc", ],
[ " rd_rt" => "%7.1f", "read_rtime", ],
[ " wr_s" => "%7.1f", "writes_sec", ],
[ "wr_avkb" => "%7.1f", "avg_write_sz", ],
[ "wr_mb_s" => "%7.1f", "mbytes_written_sec", ],
[ "wr_mrg" => "%5.0f%%", "write_merge_pct", ],
[ "wr_cnc" => "%6.1f", "write_conc", ],
[ " wr_rt" => "%7.1f", "write_rtime", ],
[ "busy" => "%3.0f%%", "busy", ],
[ "in_prg" => "%6d", "in_progress", ],
);
my @columns_in_order = @Diskstats::columns_in_order;
my ($dev, $res) = $obj->parse_diskstats_line($line, $obj->block_size);
is_deeply( $res, \%expected_results, "parse_diskstats_line works" );
$obj->column_regex(qr/./);
my ($header, $rows, $cols) = $obj->design_print_formats();
is_deeply(
$cols,
[ map { $_->[0] } @columns_in_order ],
"design_print_formats: returns the expected columns"
);
# qr/ \A (?!.*io_s$|\s*[qs]time$) /x
$obj->column_regex(qr/cnc|rt|busy|prg|[mk]b|[dr]_s|mrg/);
my ($header, $rest, $cols) = $obj->design_print_formats();
is($header, join(" ", q{%5s %-6s}, map { $_->[0] } @columns_in_order),
"design_print_formats: sanity check for defaults");
($header, $rows, $cols) = $obj->design_print_formats();
is(
$header,
join(" ", q{%5s %-6s}, grep { $_ =~ $obj->column_regex() } map { $_->[0] } @columns_in_order),
"design_print_formats: sanity check for defaults"
);
($header, $rest, $cols) = $obj->design_print_formats(max_device_length => 10);
$obj->column_regex(qr/./);
($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10);
my $all_columns_format = join(" ", q{%5s %-10s}, map { $_->[0] } @columns_in_order);
is(
$header,
@@ -126,7 +123,7 @@ is(
);
$obj->column_regex(qr/(?!)/); # Will never match
($header, $rest, $cols) = $obj->design_print_formats(max_device_length => 10);
($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10);
is(
$header,
q{%5s %-10s },
@@ -134,7 +131,7 @@ is(
);
$obj->column_regex(qr/./);
($header, $rest, $cols) = $obj->design_print_formats(
($header, $rows, $cols) = $obj->design_print_formats(
max_device_length => 10,
columns => []
);
@@ -145,7 +142,7 @@ is(
);
$obj->column_regex(qr/./);
($header, $rest, $cols) = $obj->design_print_formats(
($header, $rows, $cols) = $obj->design_print_formats(
max_device_length => 10,
columns => [qw( busy )]
);
@@ -155,11 +152,17 @@ is(
""
);
($header, $rest, $cols) = $obj->design_print_formats(
($header, $rows, $cols) = $obj->design_print_formats(
max_device_length => 10,
columns => [map { $_->[0] } @columns_in_order],
columns => [
map { $_->[0] } @columns_in_order
],
);
is($header, $all_columns_format, "");
is(
$header,
$all_columns_format,
""
);
throws_ok( sub { $obj->design_print_formats( columns => {} ) },
qr/The columns argument to design_print_formats should be an arrayref/,
@@ -220,7 +223,7 @@ is_deeply(
$obj->filter_zeroed_rows(1);
my $print_output = output(
sub {
$obj->print_rest(
$obj->print_rows(
"SHOULDN'T PRINT THIS",
[ qw( a b c ) ],
{ a => 0, b => 0, c => 0, d => 10 }
@@ -298,13 +301,19 @@ for my $test (
my $file_with_trunk = File::Spec->catfile( $trunk, $file );
my $expected = load_file( File::Spec->catfile( "t", "pt-diskstats", "expected", "${prefix}_$filename" ) );
my $got = output(
sub {
$obj->$method(
filename => $file_with_trunk,
);
});
if ( $filename =~ /003/ && $prefix eq "disk" ) {
open my $yadda, ">", "TEMP.txt";
print { $yadda } $got;
close($yadda);
}
is($got, $expected, "$method: $filename via filename");
@@ -350,13 +359,17 @@ TS 1297205887.156653000
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
TS 1297205888.161613000
EOF
my $got = output(
sub{
$obj->$method(data => $data);
});
ok(!$got, "$method: 1 line of data between two TS lines results in no output");
{
local $TODO = "Group by all works a bit differently. Probably worth it to make all three consistent, eventually" if ($prefix eq "all");
local $EVAL_ERROR;
my $got = output( sub { $obj->$method(data => $data) }, stderr => 1 );
like(
$got,
qr/Time elapsed is/,
"$method: 1 line of data between two TS lines results in an error"
);
}
$obj->curr_ts(0);
$obj->prev_ts(0);
@@ -367,4 +380,4 @@ EOF
qr/Time elapsed is/,
"$test->{class}, ->_calc_deltas fails if the time elapsed is 0"
);
}
}