From baeef02b2ab2bdf93e33880ef5d8b7750d2624b9 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Sun, 14 Jan 2024 14:57:00 +0000
Subject: [PATCH v1] Fix test failure in 038_save_logical_slots_shutdown.pl

On some machines, it was detected that the shutdown checkpoint WAL
record that gets generated as part of the publisher restart below
falls exactly in the new page in the WAL file. Due to this, the
latest checkpoint location and confirmed flush check in
compare_confirmed_flush() was failing. Hence, we advance WAL by 1
segment before generating some data so that the shutdown
checkpoint doesn't fall exactly in the new WAL file page.
---
 .../recovery/t/038_save_logical_slots_shutdown.pl     | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/test/recovery/t/038_save_logical_slots_shutdown.pl b/src/test/recovery/t/038_save_logical_slots_shutdown.pl
index 5a4f5dc1d4..3da4f55ce7 100644
--- a/src/test/recovery/t/038_save_logical_slots_shutdown.pl
+++ b/src/test/recovery/t/038_save_logical_slots_shutdown.pl
@@ -60,6 +60,14 @@ $node_subscriber->start;
 $node_publisher->safe_psql('postgres', "CREATE TABLE test_tbl (id int)");
 $node_subscriber->safe_psql('postgres', "CREATE TABLE test_tbl (id int)");
 
+# On some machines, it was detected that the shutdown checkpoint WAL record
+# that gets generated as part of the publisher restart below falls exactly in
+# the new page in the WAL file. Due to this, the latest checkpoint location and
+# confirmed flush check in compare_confirmed_flush() was failing. Hence, we
+# advance WAL by 1 segment before generating some data so that the shutdown
+# checkpoint doesn't fall exactly in the new WAL file page.
+$node_publisher->advance_wal(1);
+
 # Insert some data
 $node_publisher->safe_psql('postgres',
 	"INSERT INTO test_tbl VALUES (generate_series(1, 5));");
@@ -81,6 +89,9 @@ is($result, qq(5), "check initial copy was done");
 
 my $offset = -s $node_publisher->logfile;
 
+# Note: Don't insert any data on the publisher that may cause the shutdown
+# checkpoint to fall in new WAL file. See the note around advance_wal above.
+
 # Restart the publisher to ensure that the slot will be flushed if required
 $node_publisher->restart();
 
-- 
2.34.1

