mirror of
https://github.com/postgres/postgres.git
synced 2026-04-20 22:00:13 -04:00
The test for re-running checksum enabling was only checking for the data checksum state to transition to 'on', but didn't account for the launcher process having had time to exit, thus getting an error instead of the expected no-op. Adding a pg_stat_activity check for the launcher exiting resolves the error, verified by inducing delay in the launcher. Also wrap a variable only used in injection point tests within the correct USE macros to avoid warning for an unused variable. All per the buildfarm. Author: Daniel Gustafsson <daniel@yesql.se> Reported-by: Buildfarm Discussion: https://postgr.es/m/1CB288C9-564B-4664-B096-C2F4377D17AB@yesql.se
67 lines
2.4 KiB
Perl
67 lines
2.4 KiB
Perl
|
|
# Copyright (c) 2026, PostgreSQL Global Development Group
|
|
|
|
# Test suite for testing enabling data checksums in an online cluster
|
|
use strict;
|
|
use warnings FATAL => 'all';
|
|
|
|
use PostgreSQL::Test::Cluster;
|
|
use PostgreSQL::Test::Utils;
|
|
use Test::More;
|
|
|
|
use FindBin;
|
|
use lib $FindBin::RealBin;
|
|
|
|
use DataChecksums::Utils;
|
|
|
|
# Initialize node with checksums disabled.
|
|
my $node = PostgreSQL::Test::Cluster->new('basic_node');
|
|
$node->init(no_data_checksums => 1);
|
|
$node->start;
|
|
|
|
# Create some content to have un-checksummed data in the cluster
|
|
$node->safe_psql('postgres',
|
|
"CREATE TABLE t AS SELECT generate_series(1,10000) AS a;");
|
|
|
|
# Ensure that checksums are turned off
|
|
test_checksum_state($node, 'off');
|
|
|
|
# Enable data checksums and wait for the state transition to 'on'
|
|
enable_data_checksums($node, wait => 'on');
|
|
|
|
# Run a dummy query just to make sure we can read back data
|
|
my $result =
|
|
$node->safe_psql('postgres', "SELECT count(*) FROM t WHERE a > 1 ");
|
|
is($result, '9999', 'ensure checksummed pages can be read back');
|
|
|
|
# Enable data checksums again which should be a no-op so we explicitly don't
|
|
# wait for any state transition as none should happen here. Make sure to let
|
|
# any running launcher finish in case it's still wrapping up.
|
|
$result = $node->poll_query_until('postgres',
|
|
"SELECT count(*) = 0 FROM pg_catalog.pg_stat_activity WHERE backend_type = 'datachecksum launcher';"
|
|
);
|
|
enable_data_checksums($node);
|
|
test_checksum_state($node, 'on');
|
|
# ..and make sure we can still read/write data
|
|
$node->safe_psql('postgres', "UPDATE t SET a = a + 1;");
|
|
$result = $node->safe_psql('postgres', "SELECT count(*) FROM t WHERE a > 1");
|
|
is($result, '10000', 'ensure checksummed pages can be read back');
|
|
|
|
# Disable checksums again and wait for the state transition
|
|
disable_data_checksums($node, wait => 1);
|
|
|
|
# Test reading data again
|
|
$result = $node->safe_psql('postgres', "SELECT count(*) FROM t WHERE a > 1");
|
|
is($result, '10000', 'ensure previously checksummed pages can be read back');
|
|
|
|
# Re-enable checksums and make sure that the underlying data has changed to
|
|
# ensure that checksums will be different.
|
|
$node->safe_psql('postgres', "UPDATE t SET a = a + 1;");
|
|
enable_data_checksums($node, wait => 'on');
|
|
|
|
# Run a dummy query just to make sure we can read back the data
|
|
$result = $node->safe_psql('postgres', "SELECT count(*) FROM t WHERE a > 1");
|
|
is($result, '10000', 'ensure checksummed pages can be read back');
|
|
|
|
$node->stop;
|
|
done_testing();
|