diff options
Diffstat (limited to 't/02_backends.t')
-rw-r--r-- | t/02_backends.t | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/t/02_backends.t b/t/02_backends.t index 73933c87c..609d8ab55 100644 --- a/t/02_backends.t +++ b/t/02_backends.t @@ -16,13 +16,16 @@ my $cp = CP_Testing->new( {default_action => 'backends'} ); $dbh = $cp->test_database_handle(); +my $ver = $dbh->{pg_server_version}; +my $goodver = $ver >= 80200 ? 1 : 0; + ## Check current number of connections: should be 1 (for recent versions of PG) $SQL = 'SELECT count(*) FROM pg_stat_activity'; $count = $dbh->selectall_arrayref($SQL)->[0][0]; $t=q{Current number of backends is one (ourselves)}; -is ($count, 1, $t); -1==$count or BAIL_OUT "Cannot continue unless we start from a sane connection count\n"; +$count <= 1 or BAIL_OUT "Cannot continue unless we start from a sane connection count\n"; +pass $t; $host = $cp->get_host(); @@ -37,13 +40,17 @@ $t=qq{$S returned correct host name}; like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\)}, $t); $t=qq{$S returned correct connection count}; -like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t); +SKIP: { + skip 'Cannot test backends completely with older version of Postgres', 3; + + like ($result, qr{^POSTGRES_BACKENDS 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); + $t=qq{$S returned correct percentage}; + like ($result, qr{^POSTGRES_BACKENDS 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); + $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); +} $t=qq{$S fails when called with an invalid option}; like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t); @@ -72,12 +79,15 @@ $t=qq{$S fails when the critical option is a negative percent}; like ($cp->run('-c -10%'), qr{^ERROR: Cannot specify a negative percent}, $t); $t=qq{$S with the 'noidle' option returns expected result}; -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t); +my $num = $goodver ? 2 : 1; +like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t); $dbh2 = $cp->get_fresh_dbh(); $dbh2->do('SELECT 123'); -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 3 of 10 connections}, $t); +$num++ if $goodver; +like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ $num of 10 connections}, $t); $dbh2->commit(); -like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t); +$num = $goodver ? 2 : '(?:1|2)'; +like ($cp->run('-noidle'), qr{^POSTGRES_BACKENDS 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); @@ -85,74 +95,78 @@ like ($cp->run('--critical=1 --warning=0'), qr{^POSTGRES_BACKENDS 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 3'), qr{^POSTGRES_BACKENDS 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); $t=qq{$S works with warning option as an percentage}; like ($cp->run('-w 20%'), qr{^POSTGRES_BACKENDS WARNING}, $t); -like ($cp->run('-w 30%'), 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); $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 -8'), qr{^POSTGRES_BACKENDS OK}, $t); +$num = $goodver ? 8 : 9; +like ($cp->run("-w -$num"), qr{^POSTGRES_BACKENDS 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 3'), qr{^POSTGRES_BACKENDS 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); $t=qq{$S works with critical option as an percentage}; like ($cp->run('-c 20%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t); -like ($cp->run('-c 30%'), 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); $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 -8'), qr{^POSTGRES_BACKENDS OK}, $t); +$num = $goodver ? 8 : 9; +like ($cp->run("-c -$num"), qr{^POSTGRES_BACKENDS OK}, $t); $t=qq{$S works when no items caught by pg_stat_activity}; -$cp->drop_schema_if_exists($fakeschema); +$cp->drop_schema_if_exists(); $cp->create_fake_pg_table('pg_stat_activity'); like ($cp->run(), qr{^POSTGRES_BACKENDS 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); -$cp->remove_fake_pg_table('pg_stat_activity'); - $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); -$cp->remove_fake_pg_table('pg_settings'); +$cp->drop_schema_if_exists(); $t=qq{$S returns correct MRTG output when rows found}; -is ($cp->run('--output=MRTG'), qq{3\n0\n\nDB=postgres Max connections=10\n}, $t); +$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); $t=qq{$S works when include has valid database}; -like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t); +$num = $goodver ? 3 : 2; +like ($cp->run('--include=postgres'), qr{POSTGRES_BACKENDS OK: .+$num of 10}, $t); $t=qq{$S works when exclude forces no matches}; like ($cp->run('--exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t); $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{POSTGRES_BACKENDS OK: .+$num 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{POSTGRES_BACKENDS OK: .+$num 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{POSTGRES_BACKENDS OK: .+$num 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); +like ($cp->run('--include=postgres'), qr{ \| time=(\d\.\d\d) ardala=0 beedeebeedee=0 postgres=$num}, $t); -$cp->drop_schema_if_exists($fakeschema); +$cp->drop_schema_if_exists(); exit; |