diff options
author | Greg Sabino Mullane | 2009-04-14 03:28:54 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2009-04-14 03:28:54 +0000 |
commit | fa50b54e30ab19d198f575be148897ae6edeb591 (patch) | |
tree | 30ee0d37bec990ba351d87485b07da18ca849f7c | |
parent | 44f461742b45ead9c8d0c6e44bb56692447eb64c (diff) |
Add two new tests for fsm_pages and fsm_relations.
Minor tweak to version test, adjust CP_Testing.pm a little.
-rw-r--r-- | t/02_fsm_pages.t | 76 | ||||
-rw-r--r-- | 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 000000000..fd2a54253 --- /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 000000000..aacdaf3c7 --- /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; |