Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 46dea24

Browse files
committed
Add TAP test for archive_cleanup_command and recovery_end_command
This adds tests checking for the execution of both commands. The recovery test 002_archiving.pl is nicely adapted to that, as promotion is triggered already twice there, and even if any of those commands fail they don't affect recovery or promotion. A command success is checked using a file generated by an "echo" command, that should be able to work in all the buildfarm environments, even Msys (but we'll know soon about that). Command failure is tested with an "echo" command that points to a path that does not exist, scanning the backend logs to make sure that the failure happens. Both rely on the backend triggering the commands from the root of the data folder, making its logic more robust. Thanks to Neha Sharma for the extra tests on Windows. Author: Amul Sul, Michael Paquier Reviewed-by: Andres Freund, Euler Taveira Discussion: https://postgr.es/m/CAAJ_b95R_c4T5moq30qsybSU=eDzDHm=4SPiAWaiMWc2OW7=1Q@mail.gmail.com
1 parent cc1853b commit 46dea24

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/test/recovery/t/002_archiving.pl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use warnings;
77
use PostgreSQL::Test::Cluster;
88
use PostgreSQL::Test::Utils;
9-
use Test::More tests => 3;
9+
use Test::More tests => 7;
1010
use File::Copy;
1111

1212
# Initialize primary node, doing archives
@@ -28,6 +28,17 @@
2828
has_restoring => 1);
2929
$node_standby->append_conf('postgresql.conf',
3030
"wal_retrieve_retry_interval = '100ms'");
31+
32+
# Set archive_cleanup_command and recovery_end_command, checking their
33+
# execution by the backend with dummy commands.
34+
my $data_dir = $node_standby->data_dir;
35+
my $archive_cleanup_command_file = "archive_cleanup_command.done";
36+
my $recovery_end_command_file = "recovery_end_command.done";
37+
$node_standby->append_conf(
38+
'postgresql.conf', qq(
39+
archive_cleanup_command = 'echo archive_cleanup_done > $archive_cleanup_command_file'
40+
recovery_end_command = 'echo recovery_ended_done > $recovery_end_command_file'
41+
));
3142
$node_standby->start;
3243

3344
# Create some content on primary
@@ -36,6 +47,10 @@
3647
my $current_lsn =
3748
$node_primary->safe_psql('postgres', "SELECT pg_current_wal_lsn();");
3849

50+
# Note the presence of this checkpoint for the archive_cleanup_command
51+
# check done below, before switching to a new segment.
52+
$node_primary->safe_psql('postgres', "CHECKPOINT");
53+
3954
# Force archiving of WAL file to make it present on primary
4055
$node_primary->safe_psql('postgres', "SELECT pg_switch_wal()");
4156

@@ -53,6 +68,14 @@
5368
$node_standby->safe_psql('postgres', "SELECT count(*) FROM tab_int");
5469
is($result, qq(1000), 'check content from archives');
5570

71+
# archive_cleanup_command is executed after generating a restart point,
72+
# with a checkpoint.
73+
$node_standby->safe_psql('postgres', q{CHECKPOINT});
74+
ok( -f "$data_dir/$archive_cleanup_command_file",
75+
'archive_cleanup_command executed on checkpoint');
76+
ok( !-f "$data_dir/$recovery_end_command_file",
77+
'recovery_end_command not executed yet');
78+
5679
# Check the presence of temporary files specifically generated during
5780
# archive recovery. To ensure the presence of the temporary history
5881
# file, switch to a timeline large enough to allow a standby to recover
@@ -62,11 +85,26 @@
6285
# promoted.
6386
$node_standby->promote;
6487

88+
# recovery_end_command should have been triggered on promotion.
89+
ok( -f "$data_dir/$recovery_end_command_file",
90+
'recovery_end_command executed after promotion');
91+
6592
my $node_standby2 = PostgreSQL::Test::Cluster->new('standby2');
6693
$node_standby2->init_from_backup($node_primary, $backup_name,
6794
has_restoring => 1);
95+
96+
# Make execution of recovery_end_command fail. This should not affect
97+
# promotion, and its failure should be logged.
98+
$node_standby2->append_conf(
99+
'postgresql.conf', qq(
100+
recovery_end_command = 'echo recovery_end_failed > missing_dir/xyz.file'
101+
));
102+
68103
$node_standby2->start;
69104

105+
# Save the log location, to see the failure of recovery_end_command.
106+
my $log_location = -s $node_standby2->logfile;
107+
70108
# Now promote standby2, and check that temporary files specifically
71109
# generated during archive recovery are removed by the end of recovery.
72110
$node_standby2->promote;
@@ -75,3 +113,10 @@
75113
"RECOVERYHISTORY removed after promotion");
76114
ok( !-f "$node_standby2_data/pg_wal/RECOVERYXLOG",
77115
"RECOVERYXLOG removed after promotion");
116+
117+
# Check the logs of the standby to see that the commands have failed.
118+
my $log_contents = slurp_file($node_standby2->logfile, $log_location);
119+
like(
120+
$log_contents,
121+
qr/WARNING:.*recovery_end_command/s,
122+
"recovery_end_command failure detected in logs after promotion");

0 commit comments

Comments
 (0)