On Mon, Sep 13, 2021 at 5:56 AM Euler Taveira <eu...@eulerto.com> wrote:
>
> On Thu, Sep 9, 2021, at 8:18 AM, Amul Sul wrote:
>
> The attached patch adds a small test for recovery_end_command execution.
>
> Additional coverage is always a good thing.
>

Thanks for the confirmation.

> Currently, patch tests execution of recovery_end_command by creating
> dummy file, I am not wedded only to this approach, other suggestions
> also welcome.
>
> This test file is for archiving only. It seems 020_archive_status.pl is more
> appropriate for testing this parameter.
>

Ok, moved to 020_archive_status.pl in the attached version.

> Also, we don't have a good test for archive_cleanup_command as well, I
> am not sure how we could test that which executes with every
> restart-point.
>
> Setup a replica and stop it. It triggers a restartpoint during the shutdown.

Yeah, added that test too. I triggered the restartpoint via a
CHECKPOINT command in the attached version.

Note that I haven't tested the current version on Windows, will
cross-check that tomorrow.

Regards,
Amul
diff --git a/src/test/recovery/t/020_archive_status.pl b/src/test/recovery/t/020_archive_status.pl
index cea65735a39..a89baa93401 100644
--- a/src/test/recovery/t/020_archive_status.pl
+++ b/src/test/recovery/t/020_archive_status.pl
@@ -8,7 +8,7 @@ use strict;
 use warnings;
 use PostgresNode;
 use TestLib;
-use Test::More tests => 16;
+use Test::More tests => 20;
 use Config;
 
 my $primary = PostgresNode->new('primary');
@@ -234,3 +234,36 @@ ok( -f "$standby2_data/$segment_path_1_done"
 	  && -f "$standby2_data/$segment_path_2_done",
 	".done files created after archive success with archive_mode=always on standby"
 );
+
+# Test archive_cleanup_command and recovery_end_command execution
+my $standby3 = PostgresNode->new('standby3');
+$standby3->init_from_backup($primary, 'backup', has_restoring => 1);
+my $standby3_data = $standby3->data_dir;
+my $archive_cleanup_command_file = "$standby3_data/archive_cleanup_command.done";
+my $recovery_end_command_file = "$standby3_data/recovery_end_command.done";
+$standby3->append_conf('postgresql.conf',
+	"archive_cleanup_command = 'echo archive_cleanuped > $archive_cleanup_command_file'");
+$standby3->append_conf('postgresql.conf',
+	"recovery_end_command = 'echo recovery_ended > $recovery_end_command_file'");
+
+$standby3->start;
+$primary_lsn = $primary->lsn('write');
+$standby2->poll_query_until('postgres',
+	qq{ SELECT pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '$primary_lsn') >= 0 }
+) or die "Timed out while waiting for xlog replay on standby2";
+
+# archive_cleanup_command executed with every restart points
+ok( !-f "$archive_cleanup_command_file",
+	'archive_cleanup_command not executed yet');
+# Checkpoint will trigger restart point on standby.
+$standby3->safe_psql('postgres', q{CHECKPOINT});
+ok(-f "$archive_cleanup_command_file",
+	'archive_cleanup_command executed on checkpoint');
+
+# recovery_end_command_file executed only on recovery end which can happen on
+# promotion.
+ok( !-f "$recovery_end_command_file",
+	'recovery_end_command not executed yet');
+$standby3->promote;
+ok(-f "$recovery_end_command_file",
+	'recovery_end_command executed after promotion');

Reply via email to