]> granicus.if.org Git - postgresql/commitdiff
Clean up misuse and nonuse of poll_query_until().
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Jul 2017 18:25:09 +0000 (14:25 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Jul 2017 18:25:09 +0000 (14:25 -0400)
Several callers of PostgresNode::poll_query_until() neglected to check
for failure; I do not think that's optional.  Also, rewrite one place
that had reinvented poll_query_until() for no very good reason.

src/test/modules/commit_ts/t/003_standby_2.pl
src/test/perl/PostgresNode.pm
src/test/recovery/t/001_stream_rep.pl
src/test/recovery/t/005_replay_delay.pl
src/test/recovery/t/006_logical_decoding.pl
src/test/recovery/t/010_logical_decoding_timelines.pl

index 2fd561115cbe7040e7314c451a2fc247818f65b7..eccaf07561e409193c1ec6167c322c30143e28da 100644 (file)
@@ -55,7 +55,8 @@ $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
 $master->restart;
 
 system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote');
-$standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
+$standby->poll_query_until('postgres', "SELECT NOT pg_is_in_recovery()")
+  or die "standby never exited recovery";
 
 $standby->safe_psql('postgres', "create table t11()");
 my $standby_ts = $standby->safe_psql('postgres',
index e72c63580d47c8a227c13024b67374be9a6e5f34..f4fa6009519c56cf8f29b83eedbba47ad4150b0f 100644 (file)
@@ -43,7 +43,7 @@ PostgresNode - class representing PostgreSQL server instance
   # run query every second until it returns 't'
   # or times out
   $node->poll_query_until('postgres', q|SELECT random() < 0.1;|')
-    or print "timed out";
+    or die "timed out";
 
   # Do an online pg_basebackup
   my $ret = $node->backup('testbackup1');
index c55497d61aa9d62644cf8b6a90e42dc824341e98..15ace5f51cc713f13cbac76c3546a4cc3e6ffee4 100644 (file)
@@ -156,7 +156,8 @@ sub wait_slot_xmins
                SELECT $check_expr
                FROM pg_catalog.pg_replication_slots
                WHERE slot_name = '$slot_name';
-       ]);
+       ])
+         or die "Timed out waiting for slot xmins to advance";
 }
 
 # Fetch xmin columns from slot's pg_replication_slots row
index 94c49443a5da2db780fd1e1e7c70a6db356519be..208b278fcd1347e65fedcd63387d31ddc388a0b3 100644 (file)
@@ -44,23 +44,9 @@ $node_master->safe_psql('postgres',
 my $until_lsn =
   $node_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()");
 
-my $remaining = 90;
-while ($remaining-- > 0)
-{
-
-       # Done waiting?
-       my $replay_status = $node_standby->safe_psql('postgres',
-               "SELECT (pg_last_wal_replay_lsn() - '$until_lsn'::pg_lsn) >= 0");
-       last if $replay_status eq 't';
-
-       # No, sleep some more.
-       my $sleep = $master_insert_time + $delay - time();
-       $sleep = 1 if $sleep < 1;
-       sleep $sleep;
-}
-
-die "Maximum number of attempts reached ($remaining remain)"
-  if $remaining < 0;
+$node_standby->poll_query_until('postgres',
+       "SELECT (pg_last_wal_replay_lsn() - '$until_lsn'::pg_lsn) >= 0")
+  or die "standby never caught up";
 
 # This test is successful if and only if the LSN has been applied with at least
 # the configured apply delay.
index 72428be0bf8eeac50e4a10efcdf602321916e89f..ea389ba46361695c36d1062c6b846ed6af018f82 100644 (file)
@@ -111,9 +111,10 @@ SKIP:
                        '-S', 'otherdb_slot', '-f', '-', '--start' ]);
        $node_master->poll_query_until('otherdb',
 "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)"
-       );
+       )
+         or die "slot never became active";
        is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
-               3, 'dropping a DB with inactive logical slots fails');
+               3, 'dropping a DB with active logical slots fails');
        $pg_recvlogical->kill_kill;
        is($node_master->slot('otherdb_slot')->{'slot_name'},
                undef, 'logical slot still exists');
@@ -121,7 +122,9 @@ SKIP:
 
 $node_master->poll_query_until('otherdb',
 "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NULL)"
-);
+)
+  or die "slot never became inactive";
+
 is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
        0, 'dropping a DB with inactive logical slots succeeds');
 is($node_master->slot('otherdb_slot')->{'slot_name'},
index 65f6ba2fcad6c11ba8a5dbb36d5927caa95ef7e9..ed9e4997c403d041b28dfbfa012e169c77b89227 100644 (file)
@@ -117,7 +117,9 @@ $node_master->poll_query_until(
        SELECT catalog_xmin IS NOT NULL
        FROM pg_replication_slots
        WHERE slot_name = 'phys_slot'
-       ]);
+       ])
+  or die "slot's catalog_xmin never became set";
+
 my $phys_slot = $node_master->slot('phys_slot');
 isnt($phys_slot->{'xmin'}, '', 'xmin assigned on physical slot of master');
 isnt($phys_slot->{'catalog_xmin'},
@@ -137,7 +139,8 @@ $node_master->stop('immediate');
 $node_replica->promote;
 print "waiting for replica to come up\n";
 $node_replica->poll_query_until('postgres',
-       "SELECT NOT pg_is_in_recovery();");
+       "SELECT NOT pg_is_in_recovery();")
+  or die "replica never exited recovery";
 
 $node_replica->safe_psql('postgres',
        "INSERT INTO decoding(blah) VALUES ('after failover');");