diff options
author | Greg Sabino Mullane | 2009-05-01 13:39:36 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2009-05-01 13:39:36 +0000 |
commit | 5e3b326e3c14ff9b9df191b9102e87f2c1d2d1c0 (patch) | |
tree | 3544bd761fbf435d657ce6fa33de9811d85965cb | |
parent | f87d4d898710e00f7f532f5e2d05d78da90dc0b9 (diff) |
Last of the testing tweaks. For now.
-rw-r--r-- | check_postgres.pl.html | 13 | ||||
-rw-r--r-- | index.html | 2 | ||||
-rw-r--r-- | t/02_autovac_freeze.t | 3 | ||||
-rw-r--r-- | t/02_backends.t | 74 | ||||
-rw-r--r-- | t/02_bloat.t | 1 | ||||
-rw-r--r-- | t/02_checkpoint.t | 13 | ||||
-rw-r--r-- | t/02_connection.t | 5 | ||||
-rw-r--r-- | t/02_custom_query.t | 2 | ||||
-rw-r--r-- | t/02_dbstats.t | 1 | ||||
-rw-r--r-- | t/02_disabled_triggers.t | 2 | ||||
-rw-r--r-- | t/02_disk_space.t | 4 | ||||
-rw-r--r-- | t/02_fsm_pages.t | 1 | ||||
-rw-r--r-- | t/02_last_analyze.t | 5 | ||||
-rw-r--r-- | t/02_last_vacuum.t | 5 | ||||
-rw-r--r-- | t/02_listener.t | 5 | ||||
-rw-r--r-- | t/02_locks.t | 21 | ||||
-rw-r--r-- | t/02_logfile.t | 3 | ||||
-rw-r--r-- | t/02_prepared_txns.t | 1 | ||||
-rw-r--r-- | t/02_query_runtime.t | 4 | ||||
-rw-r--r-- | t/02_query_time.t | 2 | ||||
-rw-r--r-- | t/02_relation_size.t | 4 | ||||
-rw-r--r-- | t/02_replicate_row.t | 13 | ||||
-rw-r--r-- | t/02_settings_checksum.t | 4 | ||||
-rw-r--r-- | t/02_timesync.t | 4 | ||||
-rw-r--r-- | t/02_txn_idle.t | 2 | ||||
-rw-r--r-- | t/02_txn_time.t | 2 | ||||
-rw-r--r-- | t/02_txn_wraparound.t | 2 | ||||
-rw-r--r-- | t/02_version.t | 39 | ||||
-rw-r--r-- | t/99_perlcritic.t | 1 | ||||
-rw-r--r-- | t/CP_Testing.pm | 2 |
30 files changed, 127 insertions, 113 deletions
diff --git a/check_postgres.pl.html b/check_postgres.pl.html index a6595c773..97a4a4fca 100644 --- a/check_postgres.pl.html +++ b/check_postgres.pl.html @@ -1127,20 +1127,19 @@ time and the database time. The fourth line returns the name of the database.</p </p> <h2><a name="txn_wraparound"><strong>txn_wraparound</strong></a></h2> <p>(<code>symlink: check_postgres_txn_wraparound</code>) Checks how close to transaction wraparound one or more databases are getting. -The <em>--warning</em> and <em>--critical</em> options indicate the number of transactions -left, and must be a positive integer. If either option is not given, the default -values of 1.3 and 1.4 billion are used. There is no need to run this command -more than once per database cluster. For a more detailed discussion of what this -number represents and what to do about it, please visit the page +The <em>--warning</em> and <em>--critical</em> options indicate the number of transactions done, and must be a positive integer. +If either option is not given, the default values of 1.3 and 1.4 billion are used. There is no need to run this command +more than once per database cluster. For a more detailed discussion of what this number represents and what to do about +it, please visit the page <a href="http://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND">http://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND</a></p> <p>The warning and critical values can have underscores in the number for legibility, as Perl does.</p> <p>Example 1: Check the default values for the localhost database</p> <pre> check_postgres_txn_wraparound --host=localhost</pre> -<p>Example 2: Check port 6000 and give a critical at 1.7 billion transactions left:</p> +<p>Example 2: Check port 6000 and give a critical when 1.7 billion transactions are hit:</p> <pre> check_postgres_txn_wraparound --port=6000 --critical=1_700_000_000</pre> -<p>For MRTG output, returns the highest number of transactions for all databases on line one, +<p>For MRTG output, returns the highest number of transactions for all databases on line one, while line 4 indicates which database it is.</p> <p> </p> diff --git a/index.html b/index.html index e7331f197..7d4a8062f 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,7 @@ h1 { <h1>check_postgres.pl</h1> -<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.8.0</b>, and was released on April 28, 2009.</p> +<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.8.0</b>, and was released on April 30, 2009.</p> <ul> <li><a href="/https/git.postgresql.org/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.8.0</a></li> diff --git a/t/02_autovac_freeze.t b/t/02_autovac_freeze.t index a442628cc..2b616ed07 100644 --- a/t/02_autovac_freeze.t +++ b/t/02_autovac_freeze.t @@ -20,9 +20,8 @@ $dbname = $cp->get_dbname; $host = $cp->get_host(); my $ver = $dbh->{pg_server_version}; -my $label = 'POSTGRES_AUTOVAC_FREEZE'; - my $S = q{Action 'autovac_freeze'}; +my $label = 'POSTGRES_AUTOVAC_FREEZE'; SKIP: { diff --git a/t/02_backends.t b/t/02_backends.t index 3420a5fa2..3dc1d74b5 100644 --- a/t/02_backends.t +++ b/t/02_backends.t @@ -16,6 +16,9 @@ my $cp = CP_Testing->new( {default_action => 'backends'} ); $dbh = $cp->test_database_handle(); +my $S = q{Action 'backends'}; +my $label = 'POSTGRES_BACKENDS'; + my $ver = $dbh->{pg_server_version}; my $goodver = $ver >= 80200 ? 1 : 0; @@ -31,23 +34,22 @@ $host = $cp->get_host(); $result = $cp->run(); -my $S = q{Action 'backends'}; $t=qq{$S returned expected text and OK value}; -like ($result, qr{^POSTGRES_BACKENDS OK:}, $t); +like ($result, qr{^$label OK:}, $t); $t=qq{$S returned correct host name}; -like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\)}, $t); +like ($result, qr{^$label OK: \(host:$host\)}, $t); $t=qq{$S returned correct connection count}; SKIP: { $goodver or skip 'Cannot test backends completely with older versions of Postgres', 3; - like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t); + like ($result, qr{^$label OK: \(host:$host\) 2 of 10 connections}, $t); $t=qq{$S returned correct percentage}; - like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections \(20%\)}, $t); + like ($result, qr{^$label OK: \(host:$host\) 2 of 10 connections \(20%\)}, $t); $t=qq{$S returned correct performance data}; like ($result, qr{ \| time=(\d\.\d\d) ardala=0 beedeebeedee=0 postgres=2 template0=0 template1=0\s$}, $t); @@ -81,65 +83,65 @@ like ($cp->run('-c -10%'), qr{^ERROR: Cannot specify a negative percent}, $t); $t=qq{$S with the 'noidle' option returns expected result}; my $num = $goodver ? 2 : 1; -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t); +like ($cp->run('-noidle'), qr{^$label OK:.+ $num of 10 connections}, $t); $dbh2 = $cp->get_fresh_dbh(); $dbh2->do('SELECT 123'); $num++ if $goodver; -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t); +like ($cp->run('-noidle'), qr{^$label OK:.+ $num of 10 connections}, $t); $dbh2->commit(); $num = $goodver ? 2 : '(?:1|2)'; -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t); +like ($cp->run('-noidle'), qr{^$label OK:.+ $num of 10 connections}, $t); $t=qq{$S has critical option trump the warning option}; -like ($cp->run('-w 1 -c 1'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run('--critical=1 --warning=0'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); +like ($cp->run('-w 1 -c 1'), qr{^$label CRITICAL}, $t); +like ($cp->run('--critical=1 --warning=0'), qr{^$label CRITICAL}, $t); $t=qq{$S works with warning option as an absolute number}; -like ($cp->run('-w 2'), qr{^POSTGRES_BACKENDS WARNING}, $t); +like ($cp->run('-w 2'), qr{^$label WARNING}, $t); $num = $goodver ? 3 : 2; -like ($cp->run("-w $num"), qr{^POSTGRES_BACKENDS WARNING}, $t); -like ($cp->run('-w 4'), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run("-w $num"), qr{^$label WARNING}, $t); +like ($cp->run('-w 4'), qr{^$label OK}, $t); $t=qq{$S works with warning option as an percentage}; -like ($cp->run('-w 20%'), qr{^POSTGRES_BACKENDS WARNING}, $t); -like ($cp->run("-w ${num}0%"), qr{^POSTGRES_BACKENDS WARNING}, $t); -like ($cp->run('-w 40%'), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run('-w 20%'), qr{^$label WARNING}, $t); +like ($cp->run("-w ${num}0%"), qr{^$label WARNING}, $t); +like ($cp->run('-w 40%'), qr{^$label OK}, $t); $t=qq{$S works with warning option as a negative number}; -like ($cp->run('-w -6'), qr{^POSTGRES_BACKENDS WARNING}, $t); -like ($cp->run('-w -7'), qr{^POSTGRES_BACKENDS WARNING}, $t); +like ($cp->run('-w -6'), qr{^$label WARNING}, $t); +like ($cp->run('-w -7'), qr{^$label WARNING}, $t); $num = $goodver ? 8 : 9; -like ($cp->run("-w -$num"), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run("-w -$num"), qr{^$label OK}, $t); $t=qq{$S works with critical option as an absolute number}; -like ($cp->run('-c 2'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); +like ($cp->run('-c 2'), qr{^$label CRITICAL}, $t); $num = $goodver ? 3 : 2; -like ($cp->run("-c $num"), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run('-c 4'), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run("-c $num"), qr{^$label CRITICAL}, $t); +like ($cp->run('-c 4'), qr{^$label OK}, $t); $t=qq{$S works with critical option as an percentage}; -like ($cp->run('-c 20%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run("-c ${num}0%"), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run('-c 40%'), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run('-c 20%'), qr{^$label CRITICAL}, $t); +like ($cp->run("-c ${num}0%"), qr{^$label CRITICAL}, $t); +like ($cp->run('-c 40%'), qr{^$label OK}, $t); $t=qq{$S works with critical option as a negative number}; -like ($cp->run('-c -6'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run('-c -7'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); +like ($cp->run('-c -6'), qr{^$label CRITICAL}, $t); +like ($cp->run('-c -7'), qr{^$label CRITICAL}, $t); $num = $goodver ? 8 : 9; -like ($cp->run("-c -$num"), qr{^POSTGRES_BACKENDS OK}, $t); +like ($cp->run("-c -$num"), qr{^$label OK}, $t); $t=qq{$S works when no items caught by pg_stat_activity}; $cp->drop_schema_if_exists(); $cp->create_fake_pg_table('pg_stat_activity'); -like ($cp->run(), qr{^POSTGRES_BACKENDS OK: .+No connections}, $t); +like ($cp->run(), qr{^$label OK: .+No connections}, $t); $t=qq{$S returns correct MRTG output when no rows}; is ($cp->run('--output=MRTG'), qq{0\n0\n\nDB=postgres Max connections=10\n}, $t); $t=qq{$S fails as expected when max_connections cannot be determined}; $cp->create_fake_pg_table('pg_settings'); -like ($cp->run(), qr{^POSTGRES_BACKENDS UNKNOWN: .+max_connections}, $t); +like ($cp->run(), qr{^$label UNKNOWN: .+max_connections}, $t); $cp->drop_schema_if_exists(); $t=qq{$S returns correct MRTG output when rows found}; @@ -147,31 +149,31 @@ $num = $goodver ? 3 : 2; is ($cp->run('--output=MRTG'), qq{$num\n0\n\nDB=postgres Max connections=10\n}, $t); $t=qq{$S works when include forces no matches}; -like ($cp->run('--include=foobar'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t); +like ($cp->run('--include=foobar'), qr{^$label OK: .+No connections}, $t); SKIP: { $goodver or skip 'Cannot test backends completely with older versions of Postgres', 1; $t=qq{$S works when include has valid database}; - like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t); + like ($cp->run('--include=postgres'), qr{^$label OK: .+3 of 10}, $t); } $t=qq{$S works when exclude forces no matches}; -like ($cp->run('--exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t); +like ($cp->run('--exclude=postgres'), qr{^$label OK: .+No connections}, $t); SKIP: { $goodver or skip 'Cannot test backends completely with older versions of Postgres', 4; $t=qq{$S works when exclude excludes nothing}; - like ($cp->run('--exclude=foobar'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t); + like ($cp->run('--exclude=foobar'), qr{^$label OK: .+3 of 10}, $t); $t=qq{$S works when include and exclude make a match}; - like ($cp->run('--exclude=postgres --include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t); + like ($cp->run('--exclude=postgres --include=postgres'), qr{^$label OK: .+3 of 10}, $t); $t=qq{$S works when include and exclude make a match}; - like ($cp->run('--include=postgres --exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t); + like ($cp->run('--include=postgres --exclude=postgres'), qr{^$label OK: .+3 of 10}, $t); $t=qq{$S returned correct performance data with include}; like ($cp->run('--include=postgres'), qr{ \| time=(\d\.\d\d) ardala=0 beedeebeedee=0 postgres=3}, $t); diff --git a/t/02_bloat.t b/t/02_bloat.t index 138079737..224e1dfc6 100644 --- a/t/02_bloat.t +++ b/t/02_bloat.t @@ -18,6 +18,7 @@ $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}; diff --git a/t/02_checkpoint.t b/t/02_checkpoint.t index e00813f1a..a83c05196 100644 --- a/t/02_checkpoint.t +++ b/t/02_checkpoint.t @@ -17,6 +17,7 @@ my $cp = CP_Testing->new( {default_action => 'checkpoint'} ); $dbh = $cp->test_database_handle(); my $S = q{Action 'checkpoint'}; +my $label = 'POSTGRES_CHECKPOINT'; $t=qq{$S fails when called with an invalid option}; like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); @@ -32,28 +33,28 @@ like ($cp->run('-c foo'), qr{ERROR: .+'critical'.+valid time}, $t); $t=qq{$S fails when called without a datadir option and PGDATA is not set}; delete $ENV{PGDATA}; -like ($cp->run('-c 10'), qr{ERROR: Must supply a --datadir}, $t); +like ($cp->run('-c 10'), qr{^ERROR: Must supply a --datadir}, $t); $t=qq{$S fails when called with an invalid datadir option and PGDATA is not set}; -like ($cp->run('-c 10 --datadir=foobar'), qr{ERROR: Invalid data_directory}, $t); +like ($cp->run('-c 10 --datadir=foobar'), qr{^ERROR: Invalid data_directory}, $t); my $host = $cp->get_host(); $t=qq{$S fails when called against a non datadir datadir}; -like ($cp->run(qq{-c 10 --datadir="$host"}), qr{ERROR:.+could not read the given data directory}, $t); +like ($cp->run(qq{-c 10 --datadir="$host"}), qr{^ERROR:.+could not read the given data directory}, $t); $t=qq{$S works when called for a recent checkpoint}; my $dbh = $cp->get_dbh(); $dbh->do('CHECKPOINT'); $dbh->commit(); $host =~ s/socket$//; -like ($cp->run(qq{-w 20 --datadir="$host"}), qr{POSTGRES_CHECKPOINT OK}, $t); +like ($cp->run(qq{-w 20 --datadir="$host"}), qr{^$label OK}, $t); $t=qq{$S returns a warning when checkpoint older than warning option}; sleep 2; -like ($cp->run(qq{-w 1 --datadir="$host"}), qr{WARNING:}, $t); +like ($cp->run(qq{-w 1 --datadir="$host"}), qr{^$label WARNING:}, $t); $t=qq{$S returns a critical when checkpoint older than critical option}; -like ($cp->run(qq{-c 1 --datadir="$host"}), qr{CRITICAL:}, $t); +like ($cp->run(qq{-c 1 --datadir="$host"}), qr{^$label CRITICAL:}, $t); $t=qq{$S returns the correct number of seconds}; like ($cp->run(qq{-c 1 --datadir="$host"}), qr{was \d seconds ago}, $t); diff --git a/t/02_connection.t b/t/02_connection.t index 742a0f978..7719e27c0 100644 --- a/t/02_connection.t +++ b/t/02_connection.t @@ -23,9 +23,10 @@ $SQL = 'SELECT version()'; $result = $cp->run(); my $S = q{Action 'connection'}; +my $label = 'POSTGRES_CONNECTION'; $t=qq{$S returned expected text and OK value}; -like ($result, qr{^POSTGRES_CONNECTION OK:}, $t); +like ($result, qr{^$label OK:}, $t); $t=qq{$S returned correct performance data}; like ($result, qr{ \| time=(?:\d\.\d\d)\s$}, $t); @@ -51,7 +52,7 @@ is ($cp->run('--output=MRTG'), qq{1\n0\n\n\n}, $t); $cp->fake_version('ABC'); $t=qq{$S fails if there's a fake version function}; -like ($cp->run(), qr{^POSTGRES_CONNECTION UNKNOWN:}, $t); +like ($cp->run(), qr{^$label UNKNOWN:}, $t); $cp->reset_path(); exit; diff --git a/t/02_custom_query.t b/t/02_custom_query.t index 339f2ad03..6cf20afb7 100644 --- a/t/02_custom_query.t +++ b/t/02_custom_query.t @@ -21,9 +21,9 @@ $dbh = $cp->test_database_handle(); $dbh->{AutoCommit} = 1; $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_CUSTOM_QUERY'; my $S = q{Action 'custom_query'}; +my $label = 'POSTGRES_CUSTOM_QUERY'; $t = qq{$S self-identifies correctly}; $result = $cp->run(qq{-w 0 --query="$good_query"}); diff --git a/t/02_dbstats.t b/t/02_dbstats.t index f06910135..b2f2e0231 100644 --- a/t/02_dbstats.t +++ b/t/02_dbstats.t @@ -48,3 +48,4 @@ for (qw(backends commits rollbacks read hit idxscan idxtupread idxtupfetch idxbl like($result, qr{\b$_:\d+\b}, $t1 . $_); } +exit; diff --git a/t/02_disabled_triggers.t b/t/02_disabled_triggers.t index 8d40afe56..d183d3a8c 100644 --- a/t/02_disabled_triggers.t +++ b/t/02_disabled_triggers.t @@ -20,9 +20,9 @@ my $cp = CP_Testing->new( {default_action => 'disabled_triggers'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_DISABLED_TRIGGERS'; my $S = q{Action 'disabled_triggers'}; +my $label = 'POSTGRES_DISABLED_TRIGGERS'; my $ver = $dbh->{pg_server_version}; if ($ver < 80100) { diff --git a/t/02_disk_space.t b/t/02_disk_space.t index 0f1a48ab8..3cae08fb9 100644 --- a/t/02_disk_space.t +++ b/t/02_disk_space.t @@ -18,9 +18,9 @@ $dbh = $cp->test_database_handle(); $dbh->{AutoCommit} = 1; $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = q{POSTGRES_DISK_SPACE}; my $S = q{Action 'disk_space'}; +my $label = q{POSTGRES_DISK_SPACE}; $t = qq{$S identifies self}; $result = $cp->run('-w 999z'); @@ -43,3 +43,5 @@ like ($cp->run('-w 1b'), qr{$label WARNING:}, $t); $t = qq{$S reports MRTG output}; like ($cp->run('--output=mrtg'), qr{\A\d+\n0\n\n/.*\n}, $t); + +exit; diff --git a/t/02_fsm_pages.t b/t/02_fsm_pages.t index 5aa08bde3..dd1468679 100644 --- a/t/02_fsm_pages.t +++ b/t/02_fsm_pages.t @@ -68,7 +68,6 @@ if ($ver >= 80400) { exit; } - $t=qq{$S gives normal output for empty tables}; like ($cp->run('--warning=10%'), qr{^$label OK: .+fsm page slots used: 0 of \d+}, $t); diff --git a/t/02_last_analyze.t b/t/02_last_analyze.t index a3d08c109..dccbd32f5 100644 --- a/t/02_last_analyze.t +++ b/t/02_last_analyze.t @@ -21,9 +21,8 @@ $dbname = $cp->get_dbname; $host = $cp->get_host(); my $ver = $dbh->{pg_server_version}; -my $label = 'POSTGRES_LAST_ANALYZE'; - my $S = q{Action 'last_analyze'}; +my $label = 'POSTGRES_LAST_ANALYZE'; SKIP: { @@ -64,7 +63,7 @@ $dbh->do(qq{CREATE TABLE $testtbl AS SELECT 123::INTEGER AS a FROM generate_seri $dbh->commit(); $t = qq{$S correctly finds no matching tables}; -like ($cp->run("-w 0 --exclude=~.* --include=$testtbl"), +like ($cp->run("-w 0 --include=$testtbl"), qr{No matching tables found due to exclusion}, $t); $t = qq{$S sees a recent ANALYZE}; diff --git a/t/02_last_vacuum.t b/t/02_last_vacuum.t index 3761c7d1c..38acd962d 100644 --- a/t/02_last_vacuum.t +++ b/t/02_last_vacuum.t @@ -21,9 +21,8 @@ $dbname = $cp->get_dbname; $host = $cp->get_host(); my $ver = $dbh->{pg_server_version}; -my $label = 'POSTGRES_LAST_VACUUM'; - my $S = q{Action 'last_vacuum'}; +my $label = 'POSTGRES_LAST_VACUUM'; SKIP: { @@ -60,6 +59,7 @@ like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t); $dbh->{AutoCommit} = 1; $dbh->do('VACUUM'); +$dbh->{AutoCommit} = 0; $cp->drop_table_if_exists($testtbl); $dbh->do(qq{CREATE TABLE $testtbl AS SELECT 123::INTEGER AS a FROM generate_series(1,200000)}); @@ -68,6 +68,7 @@ like ($cp->run("-w 0 --exclude=~.* --include=$testtbl"), $t = qq{$S sees a recent VACUUM}; $dbh->do("DELETE FROM $testtbl"); +$dbh->{AutoCommit} = 1; $dbh->do('VACUUM'); sleep 1; diff --git a/t/02_listener.t b/t/02_listener.t index cd47b34c5..cb0769163 100644 --- a/t/02_listener.t +++ b/t/02_listener.t @@ -20,11 +20,12 @@ $host = $cp->get_host(); $dbname = $cp->get_dbname(); my $S = q{Action 'listener'}; +my $label = 'POSTGRES_LISTENER'; $result = $cp->run('-w foo'); $t = qq{$S returned expected text and warning}; -like ($result, qr{^POSTGRES_LISTENER WARNING:}, $t); +like ($result, qr{^$label WARNING:}, $t); $t = qq{$S returned correct host name}; like ($result, qr{\(host:$host\)}, $t); @@ -39,7 +40,7 @@ $dbh->do(q{LISTEN "FOO"}) or die $dbh->errstr; $dbh->commit; $t = qq{$S returned critical as expected<}; -like ($cp->run('-c nomatch'), qr{^POSTGRES_LISTENER CRITICAL}, $t); +like ($cp->run('-c nomatch'), qr{^$label CRITICAL}, $t); $t = qq{$S found one listener via explicit name}; like ($cp->run('-w FOO'), qr{listeners found: 1\b}, $t); diff --git a/t/02_locks.t b/t/02_locks.t index 1cb3ce34f..b9d8470ee 100644 --- a/t/02_locks.t +++ b/t/02_locks.t @@ -17,6 +17,7 @@ my $cp = CP_Testing->new( {default_action => 'locks' } ); $dbh = $cp->test_database_handle(); my $S = q{Action 'locks'}; +my $label = 'POSTGRES_LOCKS'; $t=qq{$S fails when called with an invalid option}; like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); @@ -37,40 +38,40 @@ $fakelock_sth->execute($dboid,'Exclusive','t'); $dbh->commit(); $t=qq{$S returns correct OK message}; -like ($cp->run('--critical=100'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); +like ($cp->run('--critical=100'), qr{^$label OK.*total=1 }, $t); $t=qq{$S returns correct warning message}; -like ($cp->run('--warning=1'), qr{POSTGRES_LOCKS WARNING.*total locks: 1 }, $t); +like ($cp->run('--warning=1'), qr{^$label WARNING.*total locks: 1 }, $t); $t=qq{$S returns correct critical message}; -like ($cp->run('--critical=1'), qr{POSTGRES_LOCKS CRITICAL.*total locks: 1 }, $t); +like ($cp->run('--critical=1'), qr{^$label CRITICAL.*total locks: 1 }, $t); $t=qq{$S returns correct OK message for specific lock type check}; -like ($cp->run('--critical="total=10;exclusive=3"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); +like ($cp->run('--critical="total=10;exclusive=3"'), qr{^$label OK.*total=1 }, $t); $t=qq{$S returns correct OK message for specific lock type check}; -like ($cp->run('--critical="total=10;foobar=3"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); +like ($cp->run('--critical="total=10;foobar=3"'), qr{^$label OK.*total=1 }, $t); $t=qq{$S returns correct warning message for specific lock type check}; -like ($cp->run('--warning="total=10;exclusive=1"'), qr{POSTGRES_LOCKS WARNING.*total "exclusive" locks: 1 }, $t); +like ($cp->run('--warning="total=10;exclusive=1"'), qr{^$label WARNING.*total "exclusive" locks: 1 }, $t); $t=qq{$S returns correct critical message for specific lock type check}; -like ($cp->run('--critical="total=10;exclusive=1"'), qr{POSTGRES_LOCKS CRITICAL.*total "exclusive" locks: 1 }, $t); +like ($cp->run('--critical="total=10;exclusive=1"'), qr{^$label CRITICAL.*total "exclusive" locks: 1 }, $t); $t=qq{$S returns correct MRTG output}; is ($cp->run('--output=MRTG'), qq{1\n0\n\nDB: postgres\n}, $t); $t=qq{$S returns correct OK message for 'waiting' option}; -like ($cp->run('--warning="waiting=1"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); +like ($cp->run('--warning="waiting=1"'), qr{^$label OK.*total=1 }, $t); $t=qq{$S returns correct warning message for 'waiting' option}; $fakelock_sth->execute($dboid,'Exclusive','f'); $dbh->commit(); -like ($cp->run('--warning="waiting=1"'), qr{POSTGRES_LOCKS WARNING.*total "waiting" locks: 1 }, $t); +like ($cp->run('--warning="waiting=1"'), qr{^$label WARNING.*total "waiting" locks: 1 }, $t); $t=qq{$S returns correct multiple item output}; like ($cp->run('--warning="waiting=1;exclusive=2"'), - qr{POSTGRES_LOCKS WARNING.*total "waiting" locks: 1 \* total "exclusive" locks: 2 }, $t); + qr{^$label WARNING.*total "waiting" locks: 1 \* total "exclusive" locks: 2 }, $t); $cp->drop_schema_if_exists(); diff --git a/t/02_logfile.t b/t/02_logfile.t index 239cbb1e4..fff24196a 100644 --- a/t/02_logfile.t +++ b/t/02_logfile.t @@ -19,9 +19,10 @@ $dbh = $cp->test_database_handle(); $host = $cp->get_host(); $dbname = $cp->get_dbname(); -my $label = 'POSTGRES_LOGFILE'; my $S = q{Action 'logfile'}; +my $label = 'POSTGRES_LOGFILE'; + my $logfile = 'test_database_check_postgres/pg.log'; my $cmd = $cp->get_command("--logfile=$logfile"); diff --git a/t/02_prepared_txns.t b/t/02_prepared_txns.t index 56a8b0fc3..b864c41e9 100644 --- a/t/02_prepared_txns.t +++ b/t/02_prepared_txns.t @@ -83,4 +83,3 @@ for (@$info) { $dbh->{AutoCommit} = 0; exit; - diff --git a/t/02_query_runtime.t b/t/02_query_runtime.t index 29b4c4781..4571428b9 100644 --- a/t/02_query_runtime.t +++ b/t/02_query_runtime.t @@ -20,6 +20,8 @@ my $cp = CP_Testing->new( {default_action => 'query_runtime'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); + +my $S = q{Action 'query_runtime'}; my $label = 'POSTGRES_QUERY_RUNTIME'; $cp->drop_table_if_exists($testtbl); @@ -28,8 +30,6 @@ $cp->drop_view_if_exists($testview); $dbh->do(qq{CREATE TABLE "$testtbl" ("a" integer)}) or die $dbh->errstr; $dbh->commit; -my $S = q{Action 'query_runtime'}; - $t = qq{$S self-identifies correctly}; $result = $cp->run(qq{-w 0 --queryname=$testtbl}); like ($result, qr{^$label}, $t); diff --git a/t/02_query_time.t b/t/02_query_time.t index 6cab66a0c..ac41a1c08 100644 --- a/t/02_query_time.t +++ b/t/02_query_time.t @@ -17,9 +17,9 @@ my $cp = CP_Testing->new( {default_action => 'query_time'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_QUERY_TIME'; my $S = q{Action 'query_time'}; +my $label = 'POSTGRES_QUERY_TIME'; $t = qq{$S self-identifies correctly}; $result = $cp->run(q{-w 0}); diff --git a/t/02_relation_size.t b/t/02_relation_size.t index db8ccad65..596bfa202 100644 --- a/t/02_relation_size.t +++ b/t/02_relation_size.t @@ -10,16 +10,16 @@ use Test::More tests => 23; use lib 't','.'; use CP_Testing; -use vars qw/$dbh $dbname $host $t $result $user $label/; +use vars qw/$dbh $dbname $host $t $result $user/; my $cp = CP_Testing->new({default_action => 'relation_size'}); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); $user = $cp->get_user(); -$label = q{POSTGRES_RELATION_SIZE}; my $S = q{Action 'relation_size'}; +my $label = q{POSTGRES_RELATION_SIZE}; my $testtbl = 'test_relation_size'; diff --git a/t/02_replicate_row.t b/t/02_replicate_row.t index 248e59d30..0527f145a 100644 --- a/t/02_replicate_row.t +++ b/t/02_replicate_row.t @@ -17,6 +17,9 @@ my $cp = CP_Testing->new( {default_action => 'replicate-row'} ); $dbh = $cp->test_database_handle(); $dbh2 = $cp->get_fresh_dbh({dbname=>'ardala'}); +my $S = q{Action 'replicate_rows'}; +my $label = 'POSTGRES_REPLICATE_ROW'; + $SQL = q{CREATE TABLE reptest(id INT, foo TEXT)}; if (! $cp->table_exists($dbh, 'reptest')) { $dbh->do($SQL); @@ -37,8 +40,6 @@ $dbh2->do($SQL); $dbh->commit(); $dbh2->commit(); -my $S = q{Action 'replicate_rows'}; - $t=qq{$S fails when called with an invalid option}; like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); @@ -84,7 +85,7 @@ $dbh->do($SQL); $dbh2->do($SQL); $dbh->commit(); $dbh2->commit(); -like ($cp->run('DB2replicate-row', '-w 1 -repinfo=reptest,id,1,foo,yin,yang'), qr{WARNING: .+not replicated}, $t); +like ($cp->run('DB2replicate-row', '-w 1 -repinfo=reptest,id,1,foo,yin,yang'), qr{^$label WARNING: .+not replicated}, $t); $t=qq{$S reports error when we time out via critical}; $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; @@ -92,7 +93,7 @@ $dbh->do($SQL); $dbh2->do($SQL); $dbh->commit(); $dbh2->commit(); -like ($cp->run('DB2replicate-row', '-c 1 -repinfo=reptest,id,1,foo,yin,yang'), qr{CRITICAL: .+not replicated}, $t); +like ($cp->run('DB2replicate-row', '-c 1 -repinfo=reptest,id,1,foo,yin,yang'), qr{^$label CRITICAL: .+not replicated}, $t); $t=qq{$S reports error when we time out via critical with MRTG}; $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; @@ -109,7 +110,7 @@ $dbh2->{InactiveDestroy} = 1; ## Use fork to 'replicate' behind the back of the other process if (fork) { like ($cp->run('DB2replicate-row', '-c 5 -repinfo=reptest,id,1,foo,yin,yang'), - qr{^POSTGRES_REPLICATE_ROW OK:.+Row was replicated}, $t); + qr{^$label OK:.+Row was replicated}, $t); } else { sleep 1; @@ -123,7 +124,7 @@ $t=qq{$S works when rows match, reports proper delay}; $dbh->commit(); if (fork) { $result = $cp->run('DB2replicate-row', '-c 10 -repinfo=reptest,id,1,foo,yin,yang'); - like ($result, qr{^POSTGRES_REPLICATE_ROW OK:.+Row was replicated}, $t); + like ($result, qr{^$label OK:.+Row was replicated}, $t); $result =~ /time=(\d+)/ or die 'No time?'; my $time = $1; cmp_ok ($time, '>=', 3, $t); diff --git a/t/02_settings_checksum.t b/t/02_settings_checksum.t index e13477242..08decc8ce 100644 --- a/t/02_settings_checksum.t +++ b/t/02_settings_checksum.t @@ -17,9 +17,9 @@ my $cp = CP_Testing->new( {default_action => 'settings_checksum'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_SETTINGS_CHECKSUM'; my $S = q{Action 'settings_checksum'}; +my $label = 'POSTGRES_SETTINGS_CHECKSUM'; $t = qq{$S self-identifies correctly}; $result = $cp->run('--critical 0'); @@ -51,3 +51,5 @@ like ($cp->run('-c abcdabcdabcdabcdabcdabcdabcdabcd'), $t = qq{$S accepts matching checksum}; like ($cp->run("-w $true_checksum"), qr/OK.*\Qchecksum: $true_checksum\E/, $t); + +exit; diff --git a/t/02_timesync.t b/t/02_timesync.t index be4e76d4d..536a0b33d 100644 --- a/t/02_timesync.t +++ b/t/02_timesync.t @@ -17,12 +17,12 @@ my $cp = CP_Testing->new( {default_action => 'timesync'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); + +my $S = q{Action 'timesync'}; my $label = 'POSTGRES_TIMESYNC'; my $timepatt = qr{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d}; -my $S = q{Action 'timesync'}; - $t = qq{$S self-identifies correctly}; $result = $cp->run(q{-w 100}); like ($result, qr{^$label}, $t); diff --git a/t/02_txn_idle.t b/t/02_txn_idle.t index 16001d5ca..248a83c48 100644 --- a/t/02_txn_idle.t +++ b/t/02_txn_idle.t @@ -18,9 +18,9 @@ $dbh = $cp->test_database_handle(); $dbh->{AutoCommit} = 1; $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_TXN_IDLE'; my $S = q{Action 'txn_idle'}; +my $label = 'POSTGRES_TXN_IDLE'; $t = qq{$S self-identifies correctly}; $result = $cp->run(q{-w 0}); diff --git a/t/02_txn_time.t b/t/02_txn_time.t index f6a4e7443..18acecc35 100644 --- a/t/02_txn_time.t +++ b/t/02_txn_time.t @@ -18,9 +18,9 @@ $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'}; +my $label = 'POSTGRES_TXN_TIME'; my $ver = $dbh->{pg_server_version}; if ($ver < 80300) { diff --git a/t/02_txn_wraparound.t b/t/02_txn_wraparound.t index b0774387a..6b4dba07d 100644 --- a/t/02_txn_wraparound.t +++ b/t/02_txn_wraparound.t @@ -20,9 +20,9 @@ my $cp = CP_Testing->new( {default_action => 'txn_wraparound'} ); $dbh = $cp->test_database_handle(); $dbname = $cp->get_dbname; $host = $cp->get_host(); -my $label = 'POSTGRES_TXN_WRAPAROUND'; my $S = q{Action 'txn_wraparound'}; +my $label = 'POSTGRES_TXN_WRAPAROUND'; $t = qq{$S self-identifies correctly}; $result = $cp->run(); diff --git a/t/02_version.t b/t/02_version.t index e9e7e085a..fe5c54a0c 100644 --- a/t/02_version.t +++ b/t/02_version.t @@ -17,6 +17,7 @@ my $cp = CP_Testing->new( {default_action => 'version'} ); $dbh = $cp->test_database_handle(); my $S = q{Action 'version'}; +my $label = 'POSTGRES_VERSION'; $t=qq{$S fails when called with an invalid option}; like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); @@ -37,66 +38,66 @@ $t=qq{$S fails when called with invalid critical}; like ($cp->run('-c foo'), qr{ERROR: Invalid string}, $t); $t=qq{$S gives correct output for warning on two-part version}; -like ($cp->run('-w 5.2'), qr{POSTGRES_VERSION WARNING: .+expected 5.2}, $t); +like ($cp->run('-w 5.2'), qr{^$label WARNING: .+expected 5.2}, $t); $t=qq{$S gives correct output for warning on three-part version}; -like ($cp->run('-w 5.2.1'), qr{POSTGRES_VERSION WARNING: .+expected 5.2.1}, $t); +like ($cp->run('-w 5.2.1'), qr{^$label WARNING: .+expected 5.2.1}, $t); $t=qq{$S gives correct output for critical on two-part version}; -like ($cp->run('-c 6.10'), qr{POSTGRES_VERSION CRITICAL: .+expected 6.10}, $t); +like ($cp->run('-c 6.10'), qr{^$label CRITICAL: .+expected 6.10}, $t); $t=qq{$S gives correct output for critical on three-part version}; -like ($cp->run('-c 6.10.33'), qr{POSTGRES_VERSION CRITICAL: .+expected 6.10.33}, $t); +like ($cp->run('-c 6.10.33'), qr{^$label CRITICAL: .+expected 6.10.33}, $t); ## Now to pull some trickery $cp->fake_version('foobar'); $t=qq{$S gives correct output on invalid version() parse}; -like ($cp->run('-c 8.7'), qr{POSTGRES_VERSION UNKNOWN: .+Invalid query returned}, $t); +like ($cp->run('-c 8.7'), qr{^$label UNKNOWN: .+Invalid query returned}, $t); $cp->fake_version('7.8.12'); $t=qq{$S gives correct output for two-part version warning}; -like ($cp->run('-w 7.8'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t); +like ($cp->run('-w 7.8'), qr{^$label OK: .+version 7.8.12}, $t); $t=qq{$S gives correct output for two-part version warning}; -like ($cp->run('-w 5.8'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t); +like ($cp->run('-w 5.8'), qr{^$label WARNING: .+version 7.8.12}, $t); $t=qq{$S gives correct output for two-part version warning}; -like ($cp->run('-w 7.9'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t); +like ($cp->run('-w 7.9'), qr{^$label WARNING: .+version 7.8.12}, $t); $t=qq{$S gives correct output for three-part version warning}; -like ($cp->run('-w 7.8.12'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t); +like ($cp->run('-w 7.8.12'), qr{^$label OK: .+version 7.8.12}, $t); $t=qq{$S gives correct output for three-part version warning}; -like ($cp->run('-w 7.8.11'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t); +like ($cp->run('-w 7.8.11'), qr{^$label WARNING: .+version 7.8.12}, $t); $t=qq{$S gives correct output for matching three-part version warning}; -like ($cp->run('-w 7.8.13'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t); +like ($cp->run('-w 7.8.13'), qr{^$label WARNING: .+version 7.8.12}, $t); $t=qq{$S gives correct output for matching three-part version warning}; -like ($cp->run('-w 7.9.13'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t); +like ($cp->run('-w 7.9.13'), qr{^$label WARNING: .+version 7.8.12}, $t); $t=qq{$S gives correct output for two-part version critical}; -like ($cp->run('-c 7.8'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t); +like ($cp->run('-c 7.8'), qr{^$label OK: .+version 7.8.12}, $t); $t=qq{$S gives correct output for two-part version critical}; -like ($cp->run('-c 5.8'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t); +like ($cp->run('-c 5.8'), qr{^$label CRITICAL: .+version 7.8.12}, $t); $t=qq{$S gives correct output for two-part version critical}; -like ($cp->run('-c 7.9'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t); +like ($cp->run('-c 7.9'), qr{^$label CRITICAL: .+version 7.8.12}, $t); $t=qq{$S gives correct output for three-part version critical}; -like ($cp->run('-c 7.8.12'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t); +like ($cp->run('-c 7.8.12'), qr{^$label OK: .+version 7.8.12}, $t); $t=qq{$S gives correct output for three-part version critical}; -like ($cp->run('-c 7.8.11'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t); +like ($cp->run('-c 7.8.11'), qr{^$label CRITICAL: .+version 7.8.12}, $t); $t=qq{$S gives correct output for matching three-part version critical}; -like ($cp->run('-c 7.8.13'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t); +like ($cp->run('-c 7.8.13'), qr{^$label CRITICAL: .+version 7.8.12}, $t); $t=qq{$S gives correct output for matching three-part version critical}; -like ($cp->run('-c 7.9.13'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t); +like ($cp->run('-c 7.9.13'), qr{^$label CRITICAL: .+version 7.8.12}, $t); $t=qq{$S gives correct output for MRTG output}; like ($cp->run('--output=MRTG --mrtg=7.9.13'), qr{^0\n0\n\n7.8.12\n}, $t); diff --git a/t/99_perlcritic.t b/t/99_perlcritic.t index d91264fa7..0469bdbad 100644 --- a/t/99_perlcritic.t +++ b/t/99_perlcritic.t @@ -153,3 +153,4 @@ for my $filename (sort @testfiles) { pass('Finished Perl::Critic testing'); +exit; diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm index 9106abc5f..3cc2ed1bd 100644 --- a/t/CP_Testing.pm +++ b/t/CP_Testing.pm @@ -88,6 +88,8 @@ sub test_database_handle { print $cfh qq{listen_addresses = ''\n}; print $cfh qq{max_connections = 10\n}; print $cfh qq{max_fsm_pages = 99999\n}; + print $cfh qq{stats_block_level = on\n}; + print $cfh qq{stats_row_level = on\n}; ## Grab the version for finicky items if (qx{$initdb --version} !~ /(\d+)\.(\d+)/) { |