Fix some "make test" issues
authorGuillaume Lelarge <[email protected]>
Sat, 3 Sep 2011 10:21:53 +0000 (12:21 +0200)
committerGuillaume Lelarge <[email protected]>
Sat, 3 Sep 2011 17:55:31 +0000 (19:55 +0200)
* backends test issue
  Critical and warning values were wrong for the negative number check.
  And the output message for the --include check was wrong too.

* check_replicate_row issue
  The UPDATE must be executed on the first server only.

* fsm_pages and fsm_relations test issue
  The version test (ie max_fsm_* not available on 8.4 and later releases) must be done earlier.

* doc test issue
  check_standby_mode rename to make_sure_standby_mode because all check_*
  functions are expected to have documentation, but check_standby_mode is an
  internal function.

* another doc test issue
  pgbouncer_checksum documentation wasn't at the right location.

* drop_schema_if_exists issue
  There was an unexpected return in the middle of the function, and so the
  schema was never dropped.

check_postgres.pl
t/02_backends.t
t/02_fsm_pages.t
t/02_fsm_relations.t
t/CP_Testing.pm

index a3418489e344410886a05624762ad91d8ba92abc..7d9f2b0d8e0f4939848d013dda76b007a98e69b7 100755 (executable)
@@ -1243,7 +1243,7 @@ if ($opt{showtime}) {
 
 ## Check the current database mode
 our $STANDBY = 0;
-check_standby_mode() if $opt{'assume-standby-mode'};
+make_sure_standby_mode() if $opt{'assume-standby-mode'};
 
 ## We don't (usually) want to die, but want a graceful Nagios-like exit instead
 sub ndie {
@@ -1511,7 +1511,7 @@ sub do_mrtg_stats {
     do_mrtg({one => $one, two => $two, msg => $msg});
 }
 
-sub check_standby_mode {
+sub make_sure_standby_mode {
 
     ## Checks if database in standby mode
     ## Requires $ENV{PGDATA} or --datadir
@@ -1570,7 +1570,7 @@ sub check_standby_mode {
 
     return;
 
-} ## end of check_standby_mode
+} ## end of make_sure_standby_mode
 
 
 sub finishup {
@@ -2461,7 +2461,7 @@ sub run_command {
 sub setup_target_databases {
 
     ## Build a list of all databases to connect to.
-    ## Returns a list of all such databases with conenction information:
+    ## Returns a list of all such databases with connection information:
     ## -- dbuser, --dbpass, --dbservice, --port, --dbname, --host
     ##
     ## Items are determined by host, port, and db arguments
@@ -2484,7 +2484,7 @@ sub setup_target_databases {
     ## --host=a,b --host=x --port=5432,5433 --dbuser=alice --dbuser=bob --db=baz
     ## Connects three times: a-5432-alice-baz b-5433-alice-baz x-5433-bob-baz
 
-    ## Returns a list of targets as as hashref
+    ## Returns a list of targets as a hashref
 
     my $arg = shift || {};
 
@@ -5897,7 +5897,7 @@ sub check_replicate_row {
         ndie msg('rep-wrongvals', $value1, $val1, $val2);
     }
 
-    $info1 = run_command($update, { failok => 1 } );
+    $info1 = run_command($update, { dbnumber => 1, failok => 1 } );
 
     ## Make sure the update worked
     if (! defined $info1->{db}[0]) {
@@ -8628,31 +8628,6 @@ tool that can send mail when interesting events appear in your Postgres logs.
 See: http://bucardo.org/wiki/Tail_n_mail for more information).
 See also the information on the C<--get_method> option.
 
-=head2 B<pgbouncer_checksum>
-
-(C<symlink: check_postgres_pgbouncer_checksum>) Checks that all the
-pgBouncer settings are the same as last time you checked. 
-This is done by generating a checksum of a sorted list of setting names and 
-their values. Note that you shouldn't specify the database name, it will
-automatically default to pgbouncer.  Either the I<--warning> or the I<--critical> option 
-should be given, but not both. The value of each one is the checksum, a 
-32-character hexadecimal value. You can run with the special C<--critical=0> option 
-to find out an existing checksum.
-
-This action requires the Digest::MD5 module.
-
-Example 1: Find the initial checksum for pgbouncer configuration on port 6432 using the default user (usually postgres)
-
-  check_postgres_pgbouncer_checksum --port=6432 --critical=0
-
-Example 2: Make sure no settings have changed and warn if so, using the checksum from above.
-
-  check_postgres_pgbouncer_checksum --port=6432 --warning=cd2f3b5e129dc2b4f5c0f6d8d2e64231
-
-For MRTG output, returns a 1 or 0 indicating success of failure of the checksum to match. A 
-checksum must be provided as the C<--mrtg> argument. The fourth line always gives the 
-current checksum.
-
 =head2 B<pgb_pool_cl_active>
 
 =head2 B<pgb_pool_cl_waiting>
@@ -8727,6 +8702,31 @@ the fourth line gives the name of the database, plus the current
 max_client_conn. If more than one database has been queried, the one with the
 highest number of connections is output.
 
+=head2 B<pgbouncer_checksum>
+
+(C<symlink: check_postgres_pgbouncer_checksum>) Checks that all the
+pgBouncer settings are the same as last time you checked. 
+This is done by generating a checksum of a sorted list of setting names and 
+their values. Note that you shouldn't specify the database name, it will
+automatically default to pgbouncer.  Either the I<--warning> or the I<--critical> option 
+should be given, but not both. The value of each one is the checksum, a 
+32-character hexadecimal value. You can run with the special C<--critical=0> option 
+to find out an existing checksum.
+
+This action requires the Digest::MD5 module.
+
+Example 1: Find the initial checksum for pgbouncer configuration on port 6432 using the default user (usually postgres)
+
+  check_postgres_pgbouncer_checksum --port=6432 --critical=0
+
+Example 2: Make sure no settings have changed and warn if so, using the checksum from above.
+
+  check_postgres_pgbouncer_checksum --port=6432 --warning=cd2f3b5e129dc2b4f5c0f6d8d2e64231
+
+For MRTG output, returns a 1 or 0 indicating success of failure of the checksum to match. A 
+checksum must be provided as the C<--mrtg> argument. The fourth line always gives the 
+current checksum.
+
 =head2 B<prepared_txns>
 
 (C<symlink: check_postgres_prepared_txns>) Check on the age of any existing prepared transactions. 
index 255f563108dc15bfb73ea43bcc112ea4d43b073f..4dd03b67faafa9ffcd7187f23b05ddf8a184ff08 100644 (file)
@@ -123,10 +123,10 @@ 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{^$label CRITICAL}, $t);
-like ($cp->run('-c -7'), qr{^$label CRITICAL}, $t);
-$num = $goodver ? 8 : 9;
-like ($cp->run("-c -$num"), qr{^$label OK}, $t);
+like ($cp->run('-c -5'), qr{^$label OK}, $t);
+like ($cp->run('-c -6'), qr{^$label OK}, $t);
+$num = $goodver ? 7 : 8;
+like ($cp->run("-c -$num"), qr{^$label CRITICAL}, $t);
 
 $t=qq{$S works when no items caught by pg_stat_activity};
 
@@ -173,7 +173,7 @@ SKIP: {
     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\ds ardala=0;9;9;0;10 beedeebeedee=0;9;9;0;10 postgres=3;9;9;0;10}, $t);
+    like ($cp->run('--include=postgres'), qr{ \| time=\d\.\d\ds postgres=3;9;9;0;10}, $t);
 }
 
 my %dbh;
index bbe5a97e5ec5036b48247ddfc0c51d65a5bd3bee..ce3b71618f06752255d5ea5c95c8e96f8d1fe5cc 100644 (file)
@@ -28,6 +28,19 @@ 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);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver >= 80400) {
+  SKIP: {
+        skip 'Cannot test fsm_pages completely on Postgres 8.4 or higher', 3;
+    }
+
+    $t=qq{$S gives an unknown when running against a 8.4 or higher version};
+    like ($cp->run('--warning=10%'), qr{^$label UNKNOWN.*Cannot check fsm_pages}, $t);
+
+    exit;
+
+}
+
 ## Create a fake fsm 'view' for testing
 $cp->set_fake_schema();
 my $schema = $cp->get_fake_schema();
@@ -56,19 +69,6 @@ CREATE TABLE $schema.pg_freespacemap_relations (
 });
 $dbh->commit();
 
-my $ver = $dbh->{pg_server_version};
-if ($ver >= 80400) {
-  SKIP: {
-        skip 'Cannot test fsm_pages completely on Postgres 8.4 or higher', 3;
-    }
-
-    $t=qq{$S gives an unknown when running against a 8.4 or higher version};
-    like ($cp->run('--warning=10%'), qr{^$label UNKNOWN.*Cannot check fsm_pages}, $t);
-
-    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);
 
index ebb21c253765d07a7d5c8ca29505f4d98d1d2a88..0eedc24cedc1eea7f90f46f6e0070077a0304845 100644 (file)
@@ -28,6 +28,18 @@ 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);
 
+my $ver = $dbh->{pg_server_version};
+if ($ver >= 80400) {
+  SKIP: {
+        skip 'Cannot test fsm_relations completely on Postgres 8.4 or higher', 3;
+    }
+
+    $t=qq{$S gives an unknown when running against a 8.4 or higher version};
+    like ($cp->run('--warning=10%'), qr{^$label UNKNOWN.*Cannot check fsm_relations}, $t);
+
+    exit;
+}
+
 ## Create a fake fsm 'view' for testing
 $cp->set_fake_schema();
 my $schema = $cp->get_fake_schema();
@@ -56,18 +68,6 @@ CREATE TABLE $schema.pg_freespacemap_relations (
 });
 $dbh->commit();
 
-my $ver = $dbh->{pg_server_version};
-if ($ver >= 80400) {
-  SKIP: {
-        skip 'Cannot test fsm_relations completely on Postgres 8.4 or higher', 3;
-    }
-
-    $t=qq{$S gives an unknown when running against a 8.4 or higher version};
-    like ($cp->run('--warning=10%'), qr{^$label UNKNOWN.*Cannot check fsm_relations}, $t);
-
-    exit;
-}
-
 $t=qq{$S gives normal output for empty tables};
 like ($cp->run('--warning=10%'), qr{^$label OK: .+fsm relations used: 0 of \d+}, $t);
 
index 1c60f39592b562d5a1f344597308fc9459510713..6c8cf97f751bdfea7384e5bbf45e5a9fe23bace2 100644 (file)
@@ -590,7 +590,6 @@ sub drop_schema_if_exists {
     my $dbh = $self->{dbh} || die;
     $name ||= $fakeschema;
 
-       return;
     if (! exists $self->{keep_old_schema}) {
         $SQL = 'SELECT count(*) FROM pg_namespace WHERE nspname = ' . $dbh->quote($name);
         my $count = $dbh->selectall_arrayref($SQL)->[0][0];