Improve tests for recovery_target_timeline GUC.

Commit fd7d7b7191 added regression tests to verify recovery_target_timeline
settings. To confirm that invalid values are rejected, those tests started the
server with an invalid setting and then verified that startup failed. While
functionally correct, this approach was expensive because it required
setting up and starting the server for each test case.

This commit updates the tests for recovery_target_timeline to use
the simpler approach introduced by commit bffd7130 for recovery_target_xid,
using ALTER SYSTEM SET to verify that invalid settings are rejected.
This avoids the need to set up and start the server when checking invalid
recovery_target_timeline values.

Author: David Steele <david@pgbackrest.org>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwG44vZbSoBmg076G+xkR6n=Tj2=q+fVkfP7yEsyF1daFA@mail.gmail.com
This commit is contained in:
Fujii Masao 2026-03-06 16:02:09 +09:00
parent d5ea206728
commit 2007df4333

View file

@ -190,58 +190,30 @@ like(
qr/FATAL: .* recovery ended before configured recovery target was reached/,
'recovery end before target reached is a fatal error');
# Invalid timeline target
$node_standby = PostgreSQL::Test::Cluster->new('standby_9');
$node_standby->init_from_backup($node_primary, 'my_backup',
has_restoring => 1);
$node_standby->append_conf('postgresql.conf',
"recovery_target_timeline = 'bogus'");
# Invalid recovery_target_timeline tests
my ($result, $stdout, $stderr) = $node_primary->psql('postgres',
"ALTER SYSTEM SET recovery_target_timeline TO 'bogus'");
like(
$stderr,
qr/is not a valid number/,
"invalid recovery_target_timeline (bogus value)");
$res = run_log(
[
'pg_ctl',
'--pgdata' => $node_standby->data_dir,
'--log' => $node_standby->logfile,
'start',
]);
ok(!$res, 'invalid timeline target (bogus value)');
($result, $stdout, $stderr) = $node_primary->psql('postgres',
"ALTER SYSTEM SET recovery_target_timeline TO '0'");
like(
$stderr,
qr/must be between 1 and 4294967295/,
"invalid recovery_target_timeline (lower bound check)");
my $log_start = $node_standby->wait_for_log("is not a valid number");
# Timeline target out of min range
$node_standby->append_conf('postgresql.conf',
"recovery_target_timeline = '0'");
$res = run_log(
[
'pg_ctl',
'--pgdata' => $node_standby->data_dir,
'--log' => $node_standby->logfile,
'start',
]);
ok(!$res, 'invalid timeline target (lower bound check)');
$log_start =
$node_standby->wait_for_log("must be between 1 and 4294967295", $log_start);
# Timeline target out of max range
$node_standby->append_conf('postgresql.conf',
"recovery_target_timeline = '4294967296'");
$res = run_log(
[
'pg_ctl',
'--pgdata' => $node_standby->data_dir,
'--log' => $node_standby->logfile,
'start',
]);
ok(!$res, 'invalid timeline target (upper bound check)');
$log_start =
$node_standby->wait_for_log("must be between 1 and 4294967295", $log_start);
($result, $stdout, $stderr) = $node_primary->psql('postgres',
"ALTER SYSTEM SET recovery_target_timeline TO '4294967296'");
like(
$stderr,
qr/must be between 1 and 4294967295/,
"invalid recovery_target_timeline (upper bound check)");
# Invalid recovery_target_xid tests
my ($result, $stdout, $stderr) = $node_primary->psql('postgres',
($result, $stdout, $stderr) = $node_primary->psql('postgres',
"ALTER SYSTEM SET recovery_target_xid TO 'bogus'");
like(
$stderr,