Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Improve log pattern detection in recently-added TAP tests
authorMichael Paquier <michael@paquier.xyz>
Sat, 12 Jun 2021 06:29:48 +0000 (15:29 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 12 Jun 2021 06:29:48 +0000 (15:29 +0900)
ab55d74 has introduced some tests with rows found as missing in logical
replication subscriptions for partitioned tables, relying on a logic
with a lookup of the logs generated, scanning the whole file.  This
commit makes the logic more precise, by scanning the logs only from the
position before the key queries are run to the position where we check
for the logs.  This will reduce the risk of issues with log patterns
overlapping with each other if those tests get more complicated in the
future.

Per discussion with Tom Lane.

Discussion: https://postgr.es/m/YMP+Gx2S8meYYHW4@paquier.xyz
Backpatch-through: 13

src/test/subscription/t/001_rep_changes.pl
src/test/subscription/t/013_partition.pl

index b2fdb289dbfa8fd44026bf7732d28068b4dadc00..ecfba0af049cc5bd3e7b8bf9d7c4c11c00bf2b1e 100644 (file)
@@ -311,13 +311,18 @@ $node_subscriber->reload;
 
 $node_subscriber->safe_psql('postgres', "DELETE FROM tab_full_pk");
 
+# Note that the current location of the log file is not grabbed immediately
+# after reloading the configuration, but after sending one SQL command to
+# the node so as we are sure that the reloading has taken effect.
+my $log_location = -s $node_subscriber->logfile;
+
 $node_publisher->safe_psql('postgres',
    "UPDATE tab_full_pk SET b = 'quux' WHERE a = 1");
 $node_publisher->safe_psql('postgres', "DELETE FROM tab_full_pk WHERE a = 2");
 
 $node_publisher->wait_for_catchup('tap_sub');
 
-my $logfile = slurp_file($node_subscriber->logfile());
+my $logfile = slurp_file($node_subscriber->logfile, $log_location);
 ok( $logfile =~
      qr/logical replication did not find row to be updated in replication target relation "tab_full_pk"/,
    'update target row is missing');
index d0b5a55d186324de2e1d5bc127518af7a4062eb1..e2e9290b8491090b6c7b7f334a934ec7524a9b2a 100644 (file)
@@ -362,6 +362,11 @@ $node_publisher->wait_for_catchup('sub2');
 
 $node_subscriber1->safe_psql('postgres', "DELETE FROM tab1");
 
+# Note that the current location of the log file is not grabbed immediately
+# after reloading the configuration, but after sending one SQL command to
+# the node so as we are sure that the reloading has taken effect.
+my $log_location = -s $node_subscriber1->logfile;
+
 $node_publisher->safe_psql('postgres',
    "UPDATE tab1 SET b = 'quux' WHERE a = 4");
 $node_publisher->safe_psql('postgres', "DELETE FROM tab1");
@@ -369,7 +374,7 @@ $node_publisher->safe_psql('postgres', "DELETE FROM tab1");
 $node_publisher->wait_for_catchup('sub1');
 $node_publisher->wait_for_catchup('sub2');
 
-my $logfile = slurp_file($node_subscriber1->logfile());
+my $logfile = slurp_file($node_subscriber1->logfile(), $log_location);
 ok( $logfile =~
      qr/logical replication did not find row to be updated in replication target relation's partition "tab1_2_2"/,
    'update target row is missing in tab1_2_2');
@@ -700,6 +705,11 @@ $node_subscriber1->reload;
 
 $node_subscriber1->safe_psql('postgres', "DELETE FROM tab2");
 
+# Note that the current location of the log file is not grabbed immediately
+# after reloading the configuration, but after sending one SQL command to
+# the node so as we are sure that the reloading has taken effect.
+$log_location = -s $node_subscriber1->logfile;
+
 $node_publisher->safe_psql('postgres',
    "UPDATE tab2 SET b = 'quux' WHERE a = 5");
 $node_publisher->safe_psql('postgres', "DELETE FROM tab2 WHERE a = 1");
@@ -707,7 +717,7 @@ $node_publisher->safe_psql('postgres', "DELETE FROM tab2 WHERE a = 1");
 $node_publisher->wait_for_catchup('sub_viaroot');
 $node_publisher->wait_for_catchup('sub2');
 
-$logfile = slurp_file($node_subscriber1->logfile());
+$logfile = slurp_file($node_subscriber1->logfile(), $log_location);
 ok( $logfile =~
      qr/logical replication did not find row to be updated in replication target relation's partition "tab2_1"/,
    'update target row is missing in tab2_1');