From eebbc755c880071194bbd02825b4c47f11f99213 Mon Sep 17 00:00:00 2001
From: Anton Voloshin <a.voloshin@postgrespro.ru>
Date: Thu, 18 Jan 2024 14:47:52 +0300
Subject: [PATCH 2/3] fix "xl_tot_len zero" test: amend
 advance_out_of_record_splitting_zone

Tags: commitfest_hotfix
---
 src/test/recovery/t/039_end_of_wal.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/test/recovery/t/039_end_of_wal.pl b/src/test/recovery/t/039_end_of_wal.pl
index ecf9b6089de..3168d991fee 100644
--- a/src/test/recovery/t/039_end_of_wal.pl
+++ b/src/test/recovery/t/039_end_of_wal.pl
@@ -173,6 +173,8 @@ sub build_page_header
 # a couple of small records.  This inserts a few records of a fixed size, until
 # the threshold gets close enough to the end of the WAL page inserting records
 # to.
+# Also avoid the very beginning of a page: that would break a test for a
+# zero-length logical message.
 sub advance_out_of_record_splitting_zone
 {
 	my $node = shift;
@@ -180,7 +182,7 @@ sub advance_out_of_record_splitting_zone
 	my $page_threshold = $WAL_BLOCK_SIZE / 4;
 	my $end_lsn = get_insert_lsn($node);
 	my $page_offset = $end_lsn % $WAL_BLOCK_SIZE;
-	while ($page_offset >= $WAL_BLOCK_SIZE - $page_threshold)
+	while ($page_offset >= $WAL_BLOCK_SIZE - $page_threshold || $page_offset <= $SizeOfXLogShortPHD)
 	{
 		emit_message($node, $page_threshold);
 		$end_lsn = get_insert_lsn($node);
-- 
2.43.0

