[check_postgres] [commit] Test or the 'bloat' action.

check_postgres at bucardo.org check_postgres at bucardo.org
Fri Apr 24 16:20:03 UTC 2009


Committed by Greg Sabino Mullane <greg at endpoint.com>

Test or the 'bloat' action.

---
 t/02_bloat.t |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/t/02_bloat.t b/t/02_bloat.t
new file mode 100644
index 0000000..561f93f
--- /dev/null
+++ b/t/02_bloat.t
@@ -0,0 +1,70 @@
+#!perl
+
+## Test the "bloat" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Test::More tests => 26;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t/;
+
+my $cp = CP_Testing->new( {default_action => 'bloat'} );
+
+$dbh = $cp->test_database_handle();
+
+my $S = q{Action 'bloat'};
+my $label = 'POSTGRES_BLOAT';
+my $tname = 'cp_bloat_test';
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('-w=abc'), qr{must be a size or a percentage}, $t);
+like ($cp->run('-c=abc'), qr{must be a size or a percentage}, $t);
+
+local $dbh->{AutoCommit} = 1;
+$dbh->do('VACUUM FULL');
+
+$t=qq{$S returns ok for no bloat};
+like ($cp->run('-c=99GB'), qr{^$label OK: DB "postgres"}, $t);
+
+$t=qq{$S returns ok for no bloat};
+like ($cp->run('-w=10MB'), qr{^$label OK: DB "postgres"}, $t);
+
+for my $size (qw/bytes kilobytes megabytes gigabytes terabytes exabytes petabytes zettabytes/) {
+	$t=qq{$S returns ok for no bloat with a unit of $size};
+	like ($cp->run("-w=10000$size"), qr{^$label OK: DB "postgres"}, $t);
+	my $short = substr($size, 0, 1);
+	$t=qq{$S returns ok for no bloat with a unit of $short};
+	like ($cp->run("-w=10000$short"), qr{^$label OK: DB "postgres"}, $t);
+}
+
+$t=qq{$S returns correct message if no tables due to exclusion};
+like ($cp->run("-w=1% --include=foobar"), qr{^$label UNKNOWN:.+No matching relations found due to exclusion}, $t);
+
+## Fresh database should have little bloat:
+$t=qq{$S returns okay for fresh database with no bloat};
+like ($cp->run("-w=1m"), qr{^$label OK: DB "postgres"}, $t);
+
+local $dbh->{Warn} = 0;
+$dbh->do("DROP TABLE IF EXISTS $tname");
+$dbh->do("CREATE TABLE $tname AS SELECT 123::int AS foo FROM generate_series(1,10000)");
+$dbh->do("UPDATE $tname SET foo = foo") for 1..1;
+$dbh->do('ANALYZE');
+
+$t=qq{$S returns warning for bloated table};
+like ($cp->run('-w 100000'), qr{^$label WARNING:.+$tname}, $t);
+
+$t=qq{$S returns critical for bloated table};
+like ($cp->run('-c 100000'), qr{^$label CRITICAL:.+$tname}, $t);
+
+$t=qq{$S returns warning for bloated table using percentages};
+like ($cp->run('-w 10%'), qr{^$label WARNING:.+$tname}, $t);
+
+$dbh->do("DROP TABLE $tname");
+
+exit;
-- 
1.6.0.5



More information about the Check_postgres mailing list