From 6606fe3feac135955542a4ad598fa47511b099b8 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@percona.com>
Date: Mon, 17 Aug 2026 11:35:07 +0000
Subject: [PATCH v5 3/3] Test improvements based on review comments

---
 .../test_checksums/t/010_backup_straddle.pl   | 29 +++++++++----------
 .../test_checksums/t/011_standby_straddle.pl  | 24 +++++++--------
 2 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/test/modules/test_checksums/t/010_backup_straddle.pl b/src/test/modules/test_checksums/t/010_backup_straddle.pl
index fd205fd3bb8..9a5ea5f6c88 100644
--- a/src/test/modules/test_checksums/t/010_backup_straddle.pl
+++ b/src/test/modules/test_checksums/t/010_backup_straddle.pl
@@ -40,11 +40,14 @@ my $node = PostgreSQL::Test::Cluster->new('backup_node');
 $node->init(no_data_checksums => 1, allows_streaming => 1);
 # The pages rewritten while enabling must stay dirty in shared buffers until
 # the final checkpoint, otherwise they reach disk with checksums on their own
-# and nothing is left to misjudge.  Autovacuum is disabled so that nothing
-# sets hint bits behind our back, and wal_log_hints (implied by
-# allows_streaming) must be off so that setting them does not move the page
-# LSNs past the backup start.
-$node->append_conf('postgresql.conf', 'shared_buffers = 128MB');
+# and nothing is left to misjudge.  The background writer must not flush them
+# behind our back, and shared_buffers must exceed four times the table size
+# so that the scan below does not go through a ring buffer.  Autovacuum is
+# disabled so that nothing sets hint bits behind our back, and wal_log_hints
+# (implied by allows_streaming) must be off so that setting them does not
+# move the page LSNs past the backup start.
+$node->append_conf('postgresql.conf', 'shared_buffers = 32MB');
+$node->append_conf('postgresql.conf', 'bgwriter_lru_maxpages = 0');
 $node->append_conf('postgresql.conf', 'autovacuum = off');
 $node->append_conf('postgresql.conf', 'wal_log_hints = off');
 $node->start;
@@ -96,6 +99,10 @@ $node->safe_psql('postgres',
 ok($backup->finish, 'backup straddling enable completion succeeds')
   or diag("stderr: $err");
 
+# The backup must not even mention checksums: it must skip verification
+# entirely, including the warning-only path for short reads.
+unlike($err, qr/checksum/, 'straddling backup does not verify checksums');
+
 $node->safe_psql('postgres',
 	"SELECT injection_points_wakeup('datachecksums-on-before-checkpoint');");
 $node->safe_psql('postgres',
@@ -106,11 +113,6 @@ $node->poll_query_until('postgres',
 		"SELECT count(*) = 0 FROM pg_catalog.pg_stat_activity "
 	  . "WHERE backend_type = 'datachecksums launcher';");
 
-my $result = $node->safe_psql('postgres',
-	"SELECT coalesce(sum(checksum_failures), 0) FROM pg_catalog.pg_stat_database;"
-);
-is($result, '0', 'no spurious checksum failures after enable');
-
 # A backup started once enabling has completed must verify, and pass
 $node->command_ok(
 	[
@@ -173,6 +175,8 @@ $node->safe_psql('postgres',
 
 ok($backup->finish, 'backup straddling disable and re-enable succeeds')
   or diag("stderr: $err");
+unlike($err, qr/checksum/,
+	'backup straddling disable and re-enable does not verify checksums');
 
 $node->safe_psql('postgres',
 	"SELECT injection_points_wakeup('datachecksums-on-before-checkpoint');");
@@ -183,11 +187,6 @@ wait_for_checksum_state($node, 'on');
 $node->poll_query_until('postgres',
 		"SELECT count(*) = 0 FROM pg_catalog.pg_stat_activity "
 	  . "WHERE backend_type = 'datachecksums launcher';");
-
-$result = $node->safe_psql('postgres',
-	"SELECT coalesce(sum(checksum_failures), 0) FROM pg_catalog.pg_stat_database;"
-);
-is($result, '0', 'no spurious checksum failures after disable and re-enable');
 rmtree($backupdir);
 
 # A backup started once re-enabling has completed must verify, and pass
diff --git a/src/test/modules/test_checksums/t/011_standby_straddle.pl b/src/test/modules/test_checksums/t/011_standby_straddle.pl
index 2a232995af3..9423c833e10 100644
--- a/src/test/modules/test_checksums/t/011_standby_straddle.pl
+++ b/src/test/modules/test_checksums/t/011_standby_straddle.pl
@@ -187,19 +187,19 @@ $node_primary->wait_for_catchup($node_standby, 'replay',
 	$node_primary->lsn('insert'));
 
 # The rewritten pages are again only dirty in shared buffers, so the on-disk
-# pages still lack checksums.  A base backup must skip verification and pass.
-$node_standby->command_ok(
+# pages still lack checksums.  A base backup must skip verification entirely
+# and pass without mentioning checksums on stderr.  Standby backups always
+# print a NOTICE about WAL archiving, so stderr is not empty.
+$node_standby->command_checks_all(
 	[
 		'pg_basebackup', '-D',
 		$node_standby->backup_dir . '/underway', '--wal-method=none',
 		'--no-sync', '--checkpoint=fast'
 	],
+	0,
+	[qr{^$}],
+	[qr{^(?!.*checksum)}s],
 	'backup from standby while enabling is underway succeeds');
-
-$result = $node_standby->safe_psql('postgres',
-	"SELECT coalesce(sum(checksum_failures), 0) FROM pg_catalog.pg_stat_database;"
-);
-is($result, '0', 'no spurious checksum failures while enabling is underway');
 rmtree($node_standby->backup_dir . '/underway');
 
 # Release the enabling; its final checkpoint flushes the rewritten pages.
@@ -218,20 +218,18 @@ $node_primary->wait_for_catchup($node_standby, 'replay',
 	$node_primary->lsn('insert'));
 $node_standby->safe_psql('postgres', 'CHECKPOINT;');
 
-$node_standby->command_ok(
+$node_standby->command_checks_all(
 	[
 		'pg_basebackup', '-D',
 		$node_standby->backup_dir . '/after_enable', '--wal-method=none',
 		'--no-sync', '--checkpoint=fast'
 	],
+	0,
+	[qr{^$}],
+	[qr{^(?!.*checksum)}s],
 	'backup from standby after enable completion succeeds');
 rmtree($node_standby->backup_dir . '/after_enable');
 
-$result = $node_standby->safe_psql('postgres',
-	"SELECT coalesce(sum(checksum_failures), 0) FROM pg_catalog.pg_stat_database;"
-);
-is($result, '0', 'no spurious checksum failures after enable completion');
-
 $node_standby->stop;
 $node_primary->stop;
 done_testing();
-- 
2.54.0

