Skip to content

Commit fb16d2c

Browse files
committed
Make PostgreSQL::Test::Cluster compatible with all live branches
We do this via a subclass for any branch older than the minimum known to be compatible with the main package (currently release 12). This should be useful for constructing cross-version tests. In theory this could be extended back any number of versions, with varying degrees of compatibility. Reviewed by Michael Paquier and Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/a3efd19a-d5c9-fdf2-6094-4cde056a2708@dunslane.net
1 parent cd7ea75 commit fb16d2c

File tree

1 file changed

+70
-9
lines changed

1 file changed

+70
-9
lines changed

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ use Scalar::Util qw(blessed);
111111
our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
112112
$last_port_assigned, @all_nodes, $died);
113113

114+
# the minimum version we believe to be compatible with this package without
115+
# subclassing.
116+
our $min_compat = 12;
117+
114118
INIT
115119
{
116120

@@ -1063,7 +1067,7 @@ sub enable_streaming
10631067

10641068
print "### Enabling streaming replication for node \"$name\"\n";
10651069
$self->append_conf(
1066-
'postgresql.conf', qq(
1070+
$self->_recovery_file, qq(
10671071
primary_conninfo='$root_connstr'
10681072
));
10691073
$self->set_standby_mode();
@@ -1092,7 +1096,7 @@ sub enable_restoring
10921096
: qq{cp "$path/%f" "%p"};
10931097

10941098
$self->append_conf(
1095-
'postgresql.conf', qq(
1099+
$self->_recovery_file, qq(
10961100
restore_command = '$copy_command'
10971101
));
10981102
if ($standby)
@@ -1106,6 +1110,8 @@ restore_command = '$copy_command'
11061110
return;
11071111
}
11081112

1113+
sub _recovery_file { return "postgresql.conf"; }
1114+
11091115
=pod
11101116
11111117
=item $node->set_recovery_mode()
@@ -1305,15 +1311,29 @@ sub new
13051311

13061312
$node->dump_info;
13071313

1308-
# Add node to list of nodes
1309-
push(@all_nodes, $node);
1310-
13111314
$node->_set_pg_version;
13121315

1313-
my $v = $node->{_pg_version};
1316+
my $ver = $node->{_pg_version};
13141317

1315-
carp("PostgreSQL::Test::Cluster isn't fully compatible with version " . $v)
1316-
if $v < 12;
1318+
# Use a subclass as defined below (or elsewhere) if this version
1319+
# isn't fully compatible. Warn if the version is too old and thus we don't
1320+
# have a subclass of this class.
1321+
if (ref $ver && $ver < $min_compat)
1322+
{
1323+
my $maj = $ver->major(separator => '_');
1324+
my $subclass = $class . "::V_$maj";
1325+
if ($subclass->isa($class))
1326+
{
1327+
bless $node, $subclass;
1328+
}
1329+
else
1330+
{
1331+
carp "PostgreSQL::Test::Cluster isn't fully compatible with version $ver";
1332+
}
1333+
}
1334+
1335+
# Add node to list of nodes
1336+
push(@all_nodes, $node);
13171337

13181338
return $node;
13191339
}
@@ -2602,8 +2622,12 @@ sub wait_for_catchup
26022622
. "_lsn to pass "
26032623
. $target_lsn . " on "
26042624
. $self->name . "\n";
2625+
# Before release 12 walreceiver just set the application name to
2626+
# "walreceiver"
26052627
my $query =
2606-
qq[SELECT '$target_lsn' <= ${mode}_lsn AND state = 'streaming' FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';];
2628+
qq[SELECT '$target_lsn' <= ${mode}_lsn AND state = 'streaming'
2629+
FROM pg_catalog.pg_stat_replication
2630+
WHERE application_name IN ('$standby_name', 'walreceiver')];
26072631
$self->poll_query_until('postgres', $query)
26082632
or croak "timed out waiting for catchup";
26092633
print "done\n";
@@ -2890,4 +2914,41 @@ sub corrupt_page_checksum
28902914
28912915
=cut
28922916

2917+
##########################################################################
2918+
2919+
package PostgreSQL::Test::Cluster::V_11; ## no critic (ProhibitMultiplePackages)
2920+
2921+
use parent -norequire, qw(PostgreSQL::Test::Cluster);
2922+
2923+
# https://www.postgresql.org/docs/11/release-11.html
2924+
2925+
# max_wal_senders + superuser_reserved_connections must be < max_connections
2926+
# uses recovery.conf
2927+
2928+
sub _recovery_file { return "recovery.conf"; }
2929+
2930+
sub set_standby_mode
2931+
{
2932+
my $self = shift;
2933+
$self->append_conf("recovery.conf", "standby_mode = on\n");
2934+
}
2935+
2936+
sub init
2937+
{
2938+
my ($self, %params) = @_;
2939+
$self->SUPER::init(%params);
2940+
$self->adjust_conf('postgresql.conf', 'max_wal_senders',
2941+
$params{allows_streaming} ? 5 : 0);
2942+
}
2943+
2944+
##########################################################################
2945+
2946+
package PostgreSQL::Test::Cluster::V_10; ## no critic (ProhibitMultiplePackages)
2947+
2948+
use parent -norequire, qw(PostgreSQL::Test::Cluster::V_11);
2949+
2950+
# https://www.postgresql.org/docs/10/release-10.html
2951+
2952+
########################################################################
2953+
28932954
1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy