1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
# This program is open source, licensed under the PostgreSQL License.
# For license terms, see the LICENSE file.
#
# Copyright (C) 2012-2025: Open PostgreSQL Monitoring Development Group
=pod
=head1 NAME
pgNode - facet class extending PostgresNode for check_pgactivity tests
=head1 DESCRIPTION
This class should not be used directly to create objects. Its only aim is to
extend the existing PostgresNode class, imported from PostgreSQL source code,
without editing it so we can import new versions easily.
See PostgresNode documentation for original methods.
=cut
package pgNode;
use strict;
use warnings;
use Test::More;
use Time::HiRes qw(usleep);
use Cwd 'cwd';
use Config;
use PostgresNode;
BEGIN {
# set environment vars
$ENV{'TESTDIR'} = cwd;
delete $ENV{'PAGER'};
# Look for command 'true'
# It's under /bin on various Linux, under /usr/bin for macosx
if ( -x '/bin/true' ) {
$ENV{'PG_REGRESS'} = '/bin/true';
}
else {
$ENV{'PG_REGRESS'} = '/usr/bin/true';
}
}
sub new {
my $class = shift;
my $self = {};
$self->{'node'} = PostgresNode->get_new_node(@_);
bless $self, $class;
BAIL_OUT( "TAP tests does not support versions older than 8.2" )
if $self->version < 8.2;
$ENV{'CHECK_PGA_OLD_PSQL'} = 1 if $self->version < 8.4;
note('Node "', $self->{'node'}->name, '" uses version: ', $self->version);
return $self;
}
sub AUTOLOAD {
our $AUTOLOAD;
my $subname = $AUTOLOAD;
my $self = shift;
$subname =~ s/^pgNode:://;
return if $subname eq "DESTROY" and not $self->{'node'}->can("DESTROY");
return $self->{'node'}->$subname(@_);
}
# Overload wait_for_catchup to pass the PostgresNode object as param
sub wait_for_catchup {
my $self = shift;
my $stb = shift;
$self->{'node'}->wait_for_catchup($stb->{'node'}, @_);
}
=pod
=head1 METHODS
Below the changes and new methods implemented in this facet.
=over
=item $node->version()
Return the PostgreSQL backend version.
=cut
sub version {
return $_[0]->{'node'}->{_pg_version};
#die "pgNode must not be used directly to create an object"
}
=item $node->switch_wal()
Force WAL rotation.
Return the old segment filename.
=cut
sub switch_wal {
my $self = shift;
my $result;
if ($self->version >= '10') {
$result = $self->safe_psql('postgres',
'SELECT pg_walfile_name(pg_switch_wal())');
}
else {
$result = $self->safe_psql('postgres',
'SELECT pg_xlogfile_name(pg_switch_xlog())');
}
chomp $result;
return if $result eq '';
return $result;
}
=item $node->wait_for_archive($wal)
Wait for given C<$wal> to be archived.
Timeout is 30s before bailing out.
=cut
sub wait_for_archive {
my $self = shift;
my $wal = shift;
my $sleep_time = 100_000; # 0.1s
my $max_attempts = 300; # 300 * 0.1s = 30s
my $walfile = $self->archive_dir() ."/$wal";
print "# waiting for archive $walfile\n";
while ($max_attempts and not -f $walfile) {
$max_attempts--;
usleep($sleep_time);
}
if (not -f $walfile) {
print "# timeout waiting for archive $wal\n";
print TestLib::slurp_file($self->logfile);
BAIL_OUT("achiving timeout or failure");
return 0;
}
return 1;
}
=pod
=back
=head1 SEE ALSO
The original L<PostgresNode> class with further methods.
The L<TestLib> class with testing helper functions.
=cut
1;
|