From: Jeff Boes Date: Fri, 24 Apr 2009 19:40:24 +0000 (-0400) Subject: Add txn_time tests. X-Git-Tag: 2.9.0~69 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=bd0836369de8f0e1990f84c9c009822536396318;p=check_postgres.git Add txn_time tests. --- diff --git a/t/02_txn_time.t b/t/02_txn_time.t new file mode 100644 index 000000000..2dee2e73d --- /dev/null +++ b/t/02_txn_time.t @@ -0,0 +1,75 @@ +#!perl + +## Test the "txn_time" action + +use strict; +use warnings; +use Data::Dumper; +use DBI; +use Test::More tests => 14; +use lib 't','.'; +use CP_Testing; + +use vars qw/$dbh $result $t $host $dbname/; + +my $cp = CP_Testing->new( {default_action => 'txn_time'} ); + +$dbh = $cp->test_database_handle(); +$dbh->{AutoCommit} = 1; +$dbname = $cp->get_dbname; +$host = $cp->get_host(); +my $label = 'POSTGRES_TXN_TIME'; + +my $S = q{Action 'txn_time'}; + +$t = qq{$S self-identifies correctly}; +$result = $cp->run(qq{-w 0}); +like ($result, qr{^$label}, $t); + +$t = qq{$S identifies host}; +like ($result, qr{host:$host}, $t); + +$t = qq{$S accepts valid -w input}; +for ('1 second', + '1 minute', + '1 hour', + '1 day' + ) { + like ($cp->run(qq{-w "$_"}), qr/^$label/, $t . " ($_)"); +} + +$t = qq{$S rejects invalid -w input}; +for ('-1 second', + 'abc' + ) { + like ($cp->run(qq{-w "$_"}), qr/^ERROR:.*?must be a valid time/, $t . " ($_)"); +} + +$t = qq{$S flags no-match-user}; +like ($cp->run(qq{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); + +if ($cp->run(qq{-w 0 --output=simple}) > 0) { + BAIL_OUT(qq{Cannot continue with "$S" test: txn_time count > 0\nIs someone else connected to your test database?}); +} + +$t = qq{$S finds no txn}; +like ($cp->run(qq{-w 0 --include=nosuchtablename}), qr/$label OK:.*No transactions/, $t); + +$t = qq{$S identifies no running txn}; +like ($result, qr{longest txn: 0s}, $t); + +$t .= ' (MRTG)'; +is ($cp->run(qq{--output=mrtg -w 0}), qq{0\n0\n\nDB: $dbname\n}, $t); + +$t = qq{$S identifies a one-second running txn}; +my $idle_dbh = $cp->test_database_handle(); +$idle_dbh->do('SELECT 1'); +sleep(1); +like ($cp->run(qq{-w 0}), qr{longest txn: 1s}, $t); + +$t .= ' (MRTG)'; +like ($cp->run(qq{--output=mrtg -w 0}), qr{\d+\n0\n\nDB: $dbname\n}, $t); + +$idle_dbh->commit; + +exit;