diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl index 90da1662e3..0fb4e67697 100644 --- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl +++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl @@ -5,7 +5,8 @@ use strict; use warnings; use PostgreSQL::Test::Utils; use PostgreSQL::Test::Cluster; -use Test::More tests => 20; +use Test::More tests => 25; +use IPC::Run qw(pump finish timer); program_help_ok('pg_recvlogical'); program_version_ok('pg_recvlogical'); @@ -106,3 +107,44 @@ $node->command_ok( '--start', '--endpos', "$nextlsn", '--no-loop', '-f', '-' ], 'replayed a two-phase transaction'); + +## Check for a crash bug caused by replication-slot cleanup after +## pgstat shutdown. +#fire up an interactive psql session +my $in = ''; +my $out = ''; +my $timer = timer(5); +my $h = $node->interactive_psql('postgres', \$in, \$out, $timer); +like($out, qr/psql/, "print startup banner"); + +# open a transaction +$out = ""; +$in .= "BEGIN;\nCREATE TABLE a (a int);\n"; +pump $h until ($out =~ /CREATE TABLE/ || timer->is_expired); +ok(!timer->is_expired, 'background CREATE TABLE passed'); + +# this recvlogical waits for the transaction ends +ok(open(my $recvlogical, '-|', + 'pg_recvlogical', '--create-slot', '-S', 'test2', + '-d', $node->connstr('postgres')), + 'launch background pg_recvlogical'); + +$node->poll_query_until('postgres', + qq{SELECT count(*) > 0 FROM pg_stat_activity + WHERE backend_type='walsender' + AND query like 'CREATE_REPLICATION_SLOT %';}); +# stop server while it hangs. This shouldn't crash server. +$node->stop; +ok(open(my $cont, '-|', 'pg_controldata', $node->data_dir), + 'run pg_controldata'); +my $stop_result = ''; +while (<$cont>) +{ + if (/^Database cluster state: *([^ ].*)$/) + { + $stop_result = $1; + last; + } +} + +is($stop_result, 'shut down', 'server is properly shut down');