]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make new replication slot test code less racy
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Sat, 17 Jul 2021 17:19:17 +0000 (13:19 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Sat, 17 Jul 2021 17:19:17 +0000 (13:19 -0400)
The new test code added in ead9e51e8236 is racy -- it hinges on
shared-memory state, which changes before the WARNING message is logged.
Put it the other way around.

Backpatch to 13.

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/202107161809.zclasccpfcg3@alvherre.pgsql

src/test/recovery/t/019_replslot_limit.pl

index 319a41b27ba3a3fbcf299754a37ad0f148029610..921a3c4a427b34c52017c25273d21f4852c93245 100644 (file)
@@ -174,18 +174,21 @@ ok( !find_in_log(
 my $logstart = get_log_size($node_master);
 advance_wal($node_master, 7);
 
-# This slot should be broken, wait for that to happen
-$node_master->poll_query_until(
-       'postgres',
-       qq[SELECT wal_status = 'lost' FROM pg_replication_slots
-       WHERE slot_name = 'rep1']);
-
-# WARNING should be issued
-ok( find_in_log(
-               $node_master,
-               "invalidating slot \"rep1\" because its restart_lsn [0-9A-F/]+ exceeds max_slot_wal_keep_size",
-               $logstart),
-       'check that the warning is logged');
+# wait until the WARNING is issued
+my $invalidated = 0;
+for (my $i = 0; $i < 10000; $i++)
+{
+       if (find_in_log(
+                       $node_master,
+                       "invalidating slot \"rep1\" because its restart_lsn [0-9A-F/]+ exceeds max_slot_wal_keep_size",
+                       $logstart))
+       {
+               $invalidated = 1;
+               last;
+       }
+       usleep(100_000);
+}
+ok($invalidated, 'check that slot invalidation has been logged');
 
 $result = $node_master->safe_psql(
        'postgres',