[check_postgres] [commit] Add two new tests for fsm_pages and fsm_relations.
check_postgres at bucardo.org
check_postgres at bucardo.org
Wed Apr 22 20:33:14 UTC 2009
Committed by Greg Sabino Mullane <greg at endpoint.com>
Add two new tests for fsm_pages and fsm_relations.
Minor tweak to version test, adjust CP_Testing.pm a little.
---
t/02_fsm_pages.t | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
t/02_fsm_relations.t | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 155 insertions(+), 0 deletions(-)
diff --git a/t/02_fsm_pages.t b/t/02_fsm_pages.t
new file mode 100644
index 0000000..fd2a542
--- /dev/null
+++ b/t/02_fsm_pages.t
@@ -0,0 +1,76 @@
+#!perl
+
+## Test the "fsm_pages" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More tests => 7;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t/;
+
+my $cp = CP_Testing->new( {default_action => 'fsm_pages'} );
+
+$dbh = $cp->test_database_handle();
+
+my $S = q{Action 'fsm_pages'};
+
+$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('--warning=40'), qr{ERROR:.+must be a percentage}, $t);
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('--critical=50'), qr{ERROR:.+must be a percentage}, $t);
+
+## Create a fake fsm 'view' for testing
+$cp->set_fake_schema();
+my $schema = $cp->get_fake_schema();
+{
+ local $dbh->{Warn};
+ $dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_pages");
+ $dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_relations");
+}
+$dbh->do(qq{
+CREATE TABLE $schema.pg_freespacemap_pages (
+ reltablespace oid,
+ reldatabase oid,
+ relfilenode oid,
+ relblocknumber bigint,
+ bytes integer
+);
+});
+$dbh->do(qq{
+CREATE TABLE $schema.pg_freespacemap_relations (
+ reltablespace oid,
+ reldatabase oid,
+ relfilenode oid,
+ avgrequest integer,
+ interestingpages integer,
+ sortedpages integer,
+ nextpage integer
+);
+});
+$dbh->commit();
+
+$t=qq{$S gives normal output for empty tables};
+like ($cp->run('--warning=10%'), qr{^POSTGRES_FSM_PAGES OK: .+fsm page slots used: 0 of \d+}, $t);
+
+$dbh->do("INSERT INTO $schema.pg_freespacemap_pages VALUES (1663,16389,16911,34,764)");
+$dbh->do("INSERT INTO $schema.pg_freespacemap_relations VALUES (1663,16389,16911,1077,52283,52283,37176)");
+$dbh->commit();
+
+$t=qq{$S gives normal warning output};
+like ($cp->run('--warning=10%'), qr{^POSTGRES_FSM_PAGES WARNING: .+fsm page slots used: 52288 of \d+}, $t);
+
+$t=qq{$S gives normal critical output};
+like ($cp->run('--critical=5%'), qr{^POSTGRES_FSM_PAGES CRITICAL: .+fsm page slots used: 52288 of \d+}, $t);
+
+$t=qq{$S gives normal output for MRTG};
+is ($cp->run('--critical=5% --output=MRTG'), qq{34\n52288\n\n\n}, $t);
+
+exit;
diff --git a/t/02_fsm_relations.t b/t/02_fsm_relations.t
new file mode 100644
index 0000000..aacdaf3
--- /dev/null
+++ b/t/02_fsm_relations.t
@@ -0,0 +1,79 @@
+#!perl
+
+## Test the "fsm_relations" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More tests => 7;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t/;
+
+my $cp = CP_Testing->new( {default_action => 'fsm_relations'} );
+
+$dbh = $cp->test_database_handle();
+
+my $S = q{Action 'fsm_relations'};
+
+$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('--warning=40'), qr{ERROR:.+must be a percentage}, $t);
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('--critical=50'), qr{ERROR:.+must be a percentage}, $t);
+
+## Create a fake fsm 'view' for testing
+$cp->set_fake_schema();
+my $schema = $cp->get_fake_schema();
+{
+ local $dbh->{Warn};
+ $dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_pages");
+ $dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_relations");
+}
+$dbh->do(qq{
+CREATE TABLE $schema.pg_freespacemap_pages (
+ reltablespace oid,
+ reldatabase oid,
+ relfilenode oid,
+ relblocknumber bigint,
+ bytes integer
+);
+});
+$dbh->do(qq{
+CREATE TABLE $schema.pg_freespacemap_relations (
+ reltablespace oid,
+ reldatabase oid,
+ relfilenode oid,
+ avgrequest integer,
+ interestingpages integer,
+ sortedpages integer,
+ nextpage integer
+);
+});
+$dbh->commit();
+
+$t=qq{$S gives normal output for empty tables};
+like ($cp->run('--warning=10%'), qr{^POSTGRES_FSM_RELATIONS OK: .+fsm relations used: 0 of \d+}, $t);
+
+$dbh->do("INSERT INTO $schema.pg_freespacemap_pages VALUES (1663,16389,16911,34,764)");
+my $sth = $dbh->prepare("INSERT INTO $schema.pg_freespacemap_relations VALUES (?,?,?,?,?,?,?)");
+for (1..999) {
+ $sth->execute(1663,16389,16911,1077,52283,52283,37176);
+}
+$dbh->commit();
+
+$t=qq{$S gives normal warning output};
+like ($cp->run('--warning=10%'), qr{^POSTGRES_FSM_RELATIONS WARNING: .+fsm relations used: 999 of \d+}, $t);
+
+$t=qq{$S gives normal critical output};
+like ($cp->run('--critical=5%'), qr{^POSTGRES_FSM_RELATIONS CRITICAL: .+fsm relations used: 999 of \d+}, $t);
+
+$t=qq{$S gives normal output for MRTG};
+is ($cp->run('--critical=5% --output=MRTG'), qq{100\n999\n\n\n}, $t);
+
+exit;
--
1.6.0.5
More information about the Check_postgres
mailing list