2016-03-03 17:20:46 +01:00
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
PostgresNode - class representing PostgreSQL server instance
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
use PostgresNode;
|
|
|
|
|
|
|
|
my $node = get_new_node('mynode');
|
|
|
|
|
|
|
|
# Create a data directory with initdb
|
|
|
|
$node->init();
|
|
|
|
|
|
|
|
# Start the PostgreSQL server
|
|
|
|
$node->start();
|
|
|
|
|
|
|
|
# Change a setting and restart
|
|
|
|
$node->append_conf('postgresql.conf', 'hot_standby = on');
|
|
|
|
$node->restart('fast');
|
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
# run a query with psql, like:
|
|
|
|
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
|
|
|
|
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
|
|
|
|
|
|
|
|
# Run psql with a timeout, capturing stdout and stderr
|
|
|
|
# as well as the psql exit code. Pass some extra psql
|
|
|
|
# options. If there's an error from psql raise an exception.
|
|
|
|
my ($stdout, $stderr, $timed_out);
|
|
|
|
my $cmdret = $node->psql('postgres', 'SELECT pg_sleep(60)',
|
|
|
|
stdout => \$stdout, stderr => \$stderr,
|
|
|
|
timeout => 30, timed_out => \$timed_out,
|
|
|
|
extra_params => ['--single-transaction'],
|
|
|
|
on_error_die => 1)
|
|
|
|
print "Sleep timed out" if $timed_out;
|
|
|
|
|
|
|
|
# Similar thing, more convenient in common cases
|
|
|
|
my ($cmdret, $stdout, $stderr) =
|
|
|
|
$node->psql('postgres', 'SELECT 1');
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
# run query every second until it returns 't'
|
|
|
|
# or times out
|
|
|
|
$node->poll_query_until('postgres', q|SELECT random() < 0.1;|')
|
|
|
|
or print "timed out";
|
|
|
|
|
|
|
|
# Do an online pg_basebackup
|
2016-03-09 23:54:03 +01:00
|
|
|
my $ret = $node->backup('testbackup1');
|
|
|
|
|
|
|
|
# Take a backup of a running server
|
|
|
|
my $ret = $node->backup_fs_hot('testbackup2');
|
|
|
|
|
|
|
|
# Take a backup of a stopped server
|
|
|
|
$node->stop;
|
|
|
|
my $ret = $node->backup_fs_cold('testbackup3')
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
# Restore it to create a new independent node (not a replica)
|
|
|
|
my $replica = get_new_node('replica');
|
|
|
|
$replica->init_from_backup($node, 'testbackup');
|
|
|
|
$replica->start;
|
|
|
|
|
|
|
|
# Stop the server
|
|
|
|
$node->stop('fast');
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
PostgresNode contains a set of routines able to work on a PostgreSQL node,
|
|
|
|
allowing to start, stop, backup and initialize it with various options.
|
|
|
|
The set of nodes managed by a given test is also managed by this module.
|
|
|
|
|
|
|
|
In addition to node management, PostgresNode instances have some wrappers
|
2016-02-26 17:24:22 +01:00
|
|
|
around Test::More functions to run commands with an environment set up to
|
2016-02-26 01:31:52 +01:00
|
|
|
point to the instance.
|
|
|
|
|
|
|
|
The IPC::Run module is required.
|
|
|
|
|
|
|
|
=cut
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
package PostgresNode;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Config;
|
|
|
|
use Cwd;
|
|
|
|
use Exporter 'import';
|
|
|
|
use File::Basename;
|
|
|
|
use File::Spec;
|
|
|
|
use File::Temp ();
|
|
|
|
use IPC::Run;
|
|
|
|
use RecursiveCopy;
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
use Socket;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
use Test::More;
|
|
|
|
use TestLib ();
|
2016-03-03 21:58:30 +01:00
|
|
|
use Scalar::Util qw(blessed);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
our @EXPORT = qw(
|
|
|
|
get_new_node
|
|
|
|
);
|
|
|
|
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
our ($test_localhost, $test_pghost, $last_port_assigned, @all_nodes);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
2015-12-07 23:25:31 +01:00
|
|
|
INIT
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
# PGHOST is set once and for all through a single series of tests when
|
|
|
|
# this module is loaded.
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
$test_localhost = "127.0.0.1";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
$test_pghost =
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
$TestLib::windows_os ? $test_localhost : TestLib::tempdir_short;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
$ENV{PGHOST} = $test_pghost;
|
|
|
|
$ENV{PGDATABASE} = 'postgres';
|
|
|
|
|
|
|
|
# Tracking of last port value assigned to accelerate free port lookup.
|
2015-12-07 23:25:31 +01:00
|
|
|
$last_port_assigned = int(rand() * 16384) + 49152;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item PostgresNode::new($class, $name, $pghost, $pgport)
|
|
|
|
|
|
|
|
Create a new PostgresNode instance. Does not initdb or start it.
|
|
|
|
|
|
|
|
You should generally prefer to use get_new_node() instead since it takes care
|
|
|
|
of finding port numbers, registering instances for cleanup, etc.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub new
|
|
|
|
{
|
2016-03-03 17:20:46 +01:00
|
|
|
my ($class, $name, $pghost, $pgport) = @_;
|
2015-12-07 23:25:31 +01:00
|
|
|
my $testname = basename($0);
|
|
|
|
$testname =~ s/\.[^.]+$//;
|
2016-03-03 17:20:46 +01:00
|
|
|
my $self = {
|
|
|
|
_port => $pgport,
|
|
|
|
_host => $pghost,
|
|
|
|
_basedir => TestLib::tempdir("data_" . $name),
|
|
|
|
_name => $name,
|
|
|
|
_logfile => "$TestLib::log_path/${testname}_${name}.log" };
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
bless $self, $class;
|
|
|
|
$self->dump_info;
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->port()
|
|
|
|
|
|
|
|
Get the port number assigned to the host. This won't necessarily be a TCP port
|
|
|
|
open on the local host since we prefer to use unix sockets if possible.
|
|
|
|
|
|
|
|
Use $node->connstr() if you want a connection string.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub port
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{_port};
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->host()
|
|
|
|
|
|
|
|
Return the host (like PGHOST) for this instance. May be a UNIX socket path.
|
|
|
|
|
|
|
|
Use $node->connstr() if you want a connection string.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub host
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{_host};
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->basedir()
|
|
|
|
|
|
|
|
The directory all the node's files will be within - datadir, archive directory,
|
|
|
|
backups, etc.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub basedir
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{_basedir};
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->name()
|
|
|
|
|
|
|
|
The name assigned to the node at creation time.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2016-01-20 18:13:11 +01:00
|
|
|
sub name
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
|
|
|
my ($self) = @_;
|
2016-01-20 18:13:11 +01:00
|
|
|
return $self->{_name};
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->logfile()
|
|
|
|
|
|
|
|
Path to the PostgreSQL log file for this instance.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub logfile
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{_logfile};
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->connstr()
|
|
|
|
|
|
|
|
Get a libpq connection string that will establish a connection to
|
|
|
|
this node. Suitable for passing to psql, DBD::Pg, etc.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub connstr
|
|
|
|
{
|
|
|
|
my ($self, $dbname) = @_;
|
|
|
|
my $pgport = $self->port;
|
|
|
|
my $pghost = $self->host;
|
|
|
|
if (!defined($dbname))
|
|
|
|
{
|
|
|
|
return "port=$pgport host=$pghost";
|
|
|
|
}
|
|
|
|
return "port=$pgport host=$pghost dbname=$dbname";
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->data_dir()
|
|
|
|
|
|
|
|
Returns the path to the data directory. postgresql.conf and pg_hba.conf are
|
|
|
|
always here.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub data_dir
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $res = $self->basedir;
|
|
|
|
return "$res/pgdata";
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->archive_dir()
|
|
|
|
|
|
|
|
If archiving is enabled, WAL files go here.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub archive_dir
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $basedir = $self->basedir;
|
|
|
|
return "$basedir/archives";
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->backup_dir()
|
|
|
|
|
|
|
|
The output path for backups taken with $node->backup()
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub backup_dir
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $basedir = $self->basedir;
|
|
|
|
return "$basedir/backup";
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->info()
|
|
|
|
|
|
|
|
Return a string containing human-readable diagnostic information (paths, etc)
|
|
|
|
about this node.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub info
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $_info = '';
|
|
|
|
open my $fh, '>', \$_info or die;
|
|
|
|
print $fh "Name: " . $self->name . "\n";
|
|
|
|
print $fh "Data directory: " . $self->data_dir . "\n";
|
|
|
|
print $fh "Backup directory: " . $self->backup_dir . "\n";
|
|
|
|
print $fh "Archive directory: " . $self->archive_dir . "\n";
|
|
|
|
print $fh "Connection string: " . $self->connstr . "\n";
|
|
|
|
print $fh "Log file: " . $self->logfile . "\n";
|
|
|
|
close $fh or die;
|
|
|
|
return $_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->dump_info()
|
|
|
|
|
|
|
|
Print $node->info()
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub dump_info
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
2016-02-26 01:31:52 +01:00
|
|
|
print $self->info;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
# Internal method to set up trusted pg_hba.conf for replication. Not
|
|
|
|
# documented because you shouldn't use it, it's called automatically if needed.
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub set_replication_conf
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $pgdata = $self->data_dir;
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
$self->host eq $test_pghost
|
|
|
|
or die "set_replication_conf only works with the default host";
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
open my $hba, ">>$pgdata/pg_hba.conf";
|
|
|
|
print $hba "\n# Allow replication (set up by PostgresNode.pm)\n";
|
|
|
|
if (!$TestLib::windows_os)
|
|
|
|
{
|
|
|
|
print $hba "local replication all trust\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print $hba
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
"host replication all $test_localhost/32 sspi include_realm=1 map=regress\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
close $hba;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->init(...)
|
|
|
|
|
|
|
|
Initialize a new cluster for testing.
|
|
|
|
|
|
|
|
Authentication is set up so that only the current OS user can access the
|
|
|
|
cluster. On Unix, we use Unix domain socket connections, with the socket in
|
|
|
|
a directory that's only accessible to the current user to ensure that.
|
|
|
|
On Windows, we use SSPI authentication to ensure the same (by pg_regress
|
|
|
|
--config-auth).
|
|
|
|
|
|
|
|
pg_hba.conf is configured to allow replication connections. Pass the keyword
|
|
|
|
parameter hba_permit_replication => 0 to disable this.
|
|
|
|
|
2016-02-26 20:13:30 +01:00
|
|
|
WAL archiving can be enabled on this node by passing the keyword parameter
|
|
|
|
has_archiving => 1. This is disabled by default.
|
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
postgresql.conf can be set up for replication by passing the keyword
|
|
|
|
parameter allows_streaming => 1. This is disabled by default.
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
The new node is set up in a fast but unsafe configuration where fsync is
|
|
|
|
disabled.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub init
|
|
|
|
{
|
|
|
|
my ($self, %params) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
|
|
|
my $host = $self->host;
|
|
|
|
|
|
|
|
$params{hba_permit_replication} = 1
|
2016-02-26 17:24:22 +01:00
|
|
|
unless defined $params{hba_permit_replication};
|
|
|
|
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
|
2016-03-03 17:20:46 +01:00
|
|
|
$params{has_archiving} = 0 unless defined $params{has_archiving};
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
mkdir $self->backup_dir;
|
|
|
|
mkdir $self->archive_dir;
|
|
|
|
|
|
|
|
TestLib::system_or_bail('initdb', '-D', $pgdata, '-A', 'trust', '-N');
|
|
|
|
TestLib::system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
|
|
|
|
|
|
|
|
open my $conf, ">>$pgdata/postgresql.conf";
|
2016-01-20 18:13:11 +01:00
|
|
|
print $conf "\n# Added by PostgresNode.pm\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print $conf "fsync = off\n";
|
|
|
|
print $conf "log_statement = all\n";
|
|
|
|
print $conf "port = $port\n";
|
2016-02-26 17:24:22 +01:00
|
|
|
|
|
|
|
if ($params{allows_streaming})
|
|
|
|
{
|
2016-03-01 02:01:54 +01:00
|
|
|
print $conf "wal_level = replica\n";
|
2016-02-26 17:24:22 +01:00
|
|
|
print $conf "max_wal_senders = 5\n";
|
|
|
|
print $conf "wal_keep_segments = 20\n";
|
|
|
|
print $conf "max_wal_size = 128MB\n";
|
|
|
|
print $conf "shared_buffers = 1MB\n";
|
|
|
|
print $conf "wal_log_hints = on\n";
|
|
|
|
print $conf "hot_standby = on\n";
|
|
|
|
print $conf "max_connections = 10\n";
|
|
|
|
}
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
if ($TestLib::windows_os)
|
|
|
|
{
|
|
|
|
print $conf "listen_addresses = '$host'\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print $conf "unix_socket_directories = '$host'\n";
|
|
|
|
print $conf "listen_addresses = ''\n";
|
|
|
|
}
|
|
|
|
close $conf;
|
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
$self->set_replication_conf if $params{hba_permit_replication};
|
2016-03-03 17:20:46 +01:00
|
|
|
$self->enable_archiving if $params{has_archiving};
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->append_conf(filename, str)
|
|
|
|
|
|
|
|
A shortcut method to append to files like pg_hba.conf and postgresql.conf.
|
|
|
|
|
|
|
|
Does no validation or sanity checking. Does not reload the configuration
|
|
|
|
after writing.
|
|
|
|
|
|
|
|
A newline is NOT automatically appended to the string.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub append_conf
|
|
|
|
{
|
|
|
|
my ($self, $filename, $str) = @_;
|
|
|
|
|
|
|
|
my $conffile = $self->data_dir . '/' . $filename;
|
|
|
|
|
|
|
|
TestLib::append_to_file($conffile, $str);
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->backup(backup_name)
|
|
|
|
|
2016-03-09 23:54:03 +01:00
|
|
|
Create a hot backup with B<pg_basebackup> in subdirectory B<backup_name> of
|
|
|
|
B<< $node->backup_dir >>, including the transaction logs. Transaction logs are
|
|
|
|
fetched at the end of the backup, not streamed.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
2016-03-09 23:54:03 +01:00
|
|
|
You'll have to configure a suitable B<max_wal_senders> on the
|
2016-02-26 01:31:52 +01:00
|
|
|
target server since it isn't done by default.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub backup
|
|
|
|
{
|
|
|
|
my ($self, $backup_name) = @_;
|
|
|
|
my $backup_path = $self->backup_dir . '/' . $backup_name;
|
|
|
|
my $port = $self->port;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
2016-03-09 23:54:03 +01:00
|
|
|
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
TestLib::system_or_bail("pg_basebackup -D $backup_path -p $port -x");
|
|
|
|
print "# Backup finished\n";
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:54:03 +01:00
|
|
|
=item $node->backup_fs_hot(backup_name)
|
|
|
|
|
|
|
|
Create a backup with a filesystem level copy in subdirectory B<backup_name> of
|
|
|
|
B<< $node->backup_dir >>, including transaction logs.
|
|
|
|
|
|
|
|
Archiving must be enabled, as B<pg_start_backup()> and B<pg_stop_backup()> are
|
|
|
|
used. This is not checked or enforced.
|
|
|
|
|
|
|
|
The backup name is passed as the backup label to B<pg_start_backup()>.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub backup_fs_hot
|
|
|
|
{
|
|
|
|
my ($self, $backup_name) = @_;
|
|
|
|
$self->_backup_fs($backup_name, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
=item $node->backup_fs_cold(backup_name)
|
|
|
|
|
|
|
|
Create a backup with a filesystem level copy in subdirectory B<backup_name> of
|
|
|
|
B<< $node->backup_dir >>, including transaction logs. The server must be
|
|
|
|
stopped as no attempt to handle concurrent writes is made.
|
|
|
|
|
|
|
|
Use B<backup> or B<backup_fs_hot> if you want to back up a running server.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub backup_fs_cold
|
|
|
|
{
|
|
|
|
my ($self, $backup_name) = @_;
|
|
|
|
$self->_backup_fs($backup_name, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Common sub of backup_fs_hot and backup_fs_cold
|
|
|
|
sub _backup_fs
|
|
|
|
{
|
|
|
|
my ($self, $backup_name, $hot) = @_;
|
|
|
|
my $backup_path = $self->backup_dir . '/' . $backup_name;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $name = $self->name;
|
|
|
|
|
|
|
|
print "# Taking filesystem backup $backup_name from node \"$name\"\n";
|
|
|
|
|
|
|
|
if ($hot)
|
|
|
|
{
|
|
|
|
my $stdout = $self->safe_psql('postgres',
|
|
|
|
"SELECT * FROM pg_start_backup('$backup_name');");
|
|
|
|
print "# pg_start_backup: $stdout\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
RecursiveCopy::copypath(
|
|
|
|
$self->data_dir,
|
|
|
|
$backup_path,
|
|
|
|
filterfn => sub {
|
|
|
|
my $src = shift;
|
|
|
|
return ($src ne 'pg_log' and $src ne 'postmaster.pid');
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($hot)
|
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
2016-03-09 23:54:03 +01:00
|
|
|
# We ignore pg_stop_backup's return value. We also assume archiving
|
|
|
|
# is enabled; otherwise the caller will have to copy the remaining
|
|
|
|
# segments.
|
2016-06-12 10:19:56 +02:00
|
|
|
my $stdout =
|
|
|
|
$self->safe_psql('postgres', 'SELECT * FROM pg_stop_backup();');
|
2016-03-09 23:54:03 +01:00
|
|
|
print "# pg_stop_backup: $stdout\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "# Backup finished\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->init_from_backup(root_node, backup_name)
|
|
|
|
|
|
|
|
Initialize a node from a backup, which may come from this node or a different
|
|
|
|
node. root_node must be a PostgresNode reference, backup_name the string name
|
|
|
|
of a backup previously created on that node with $node->backup.
|
|
|
|
|
2016-02-26 20:13:30 +01:00
|
|
|
Does not start the node after initializing it.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
A recovery.conf is not created.
|
|
|
|
|
2016-02-26 20:13:30 +01:00
|
|
|
pg_hba.conf is configured to allow replication connections. Pass the keyword
|
|
|
|
parameter hba_permit_replication => 0 to disable this.
|
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
Streaming replication can be enabled on this node by passing the keyword
|
|
|
|
parameter has_streaming => 1. This is disabled by default.
|
|
|
|
|
2016-02-26 20:13:30 +01:00
|
|
|
Restoring WAL segments from archives using restore_command can be enabled
|
2016-02-26 20:22:53 +01:00
|
|
|
by passing the keyword parameter has_restoring => 1. This is disabled by
|
2016-02-26 20:13:30 +01:00
|
|
|
default.
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
The backup is copied, leaving the original unmodified. pg_hba.conf is
|
|
|
|
unconditionally set to enable replication connections.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub init_from_backup
|
|
|
|
{
|
2016-02-26 17:24:22 +01:00
|
|
|
my ($self, $root_node, $backup_name, %params) = @_;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
|
|
|
|
my $port = $self->port;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $node_name = $self->name;
|
|
|
|
my $root_name = $root_node->name;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
$params{has_streaming} = 0 unless defined $params{has_streaming};
|
2016-02-26 20:13:30 +01:00
|
|
|
$params{hba_permit_replication} = 1
|
2016-03-03 17:20:46 +01:00
|
|
|
unless defined $params{hba_permit_replication};
|
2016-02-26 20:13:30 +01:00
|
|
|
$params{has_restoring} = 0 unless defined $params{has_restoring};
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
print
|
2016-01-20 18:13:11 +01:00
|
|
|
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
|
|
|
|
die "Backup \"$backup_name\" does not exist at $backup_path"
|
|
|
|
unless -d $backup_path;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
mkdir $self->backup_dir;
|
|
|
|
mkdir $self->archive_dir;
|
|
|
|
|
|
|
|
my $data_path = $self->data_dir;
|
|
|
|
rmdir($data_path);
|
|
|
|
RecursiveCopy::copypath($backup_path, $data_path);
|
|
|
|
chmod(0700, $data_path);
|
|
|
|
|
|
|
|
# Base configuration for this node
|
|
|
|
$self->append_conf(
|
|
|
|
'postgresql.conf',
|
|
|
|
qq(
|
|
|
|
port = $port
|
|
|
|
));
|
2016-03-03 17:20:46 +01:00
|
|
|
$self->set_replication_conf if $params{hba_permit_replication};
|
2016-02-26 17:24:22 +01:00
|
|
|
$self->enable_streaming($root_node) if $params{has_streaming};
|
2016-02-26 20:13:30 +01:00
|
|
|
$self->enable_restoring($root_node) if $params{has_restoring};
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->start()
|
|
|
|
|
|
|
|
Wrapper for pg_ctl -w start
|
|
|
|
|
|
|
|
Start the node and wait until it is ready to accept connections.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub start
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
|
|
|
print("### Starting node \"$name\"\n");
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $ret = TestLib::system_log('pg_ctl', '-w', '-D', $self->data_dir, '-l',
|
|
|
|
$self->logfile, 'start');
|
|
|
|
|
|
|
|
if ($ret != 0)
|
|
|
|
{
|
|
|
|
print "# pg_ctl failed; logfile:\n";
|
|
|
|
print TestLib::slurp_file($self->logfile);
|
|
|
|
BAIL_OUT("pg_ctl failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->_update_pid;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->stop(mode)
|
|
|
|
|
|
|
|
Stop the node using pg_ctl -m $mode and wait for it to stop.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub stop
|
|
|
|
{
|
|
|
|
my ($self, $mode) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
2016-02-26 17:24:22 +01:00
|
|
|
$mode = 'fast' unless defined $mode;
|
Fix order of shutdown cleanup operations in PostgresNode.pm.
Previously, database clusters created by a TAP test were shut down by
DESTROY methods attached to the PostgresNode objects representing them.
The trouble with that is that if the objects survive into the final global
destruction phase (which they do), Perl executes the DESTROY methods in an
unspecified order. Thus, the order of shutdown of multiple clusters was
indeterminate, which might lead to not-very-reproducible errors getting
logged (eg from a slave whose master might or might not get killed first).
Worse, the File::Temp objects representing the temporary PGDATA directories
might get destroyed before the PostgresNode objects, resulting in attempts
to delete PGDATA directories that still have live servers in them. On
Windows, this would lead to directory deletion failures; on Unix, it
usually had no effects worse than erratic "could not open temporary
statistics file "pg_stat/global.tmp": No such file or directory" log
messages.
While none of this would affect the reported result of the TAP test, which
is already determined, it could be very confusing when one is trying to
understand from the logs what went wrong with a failed test.
To fix, do the postmaster shutdowns in an END block rather than at object
destruction time. The END block will execute at a well-defined (and
reasonable) time during script termination, and it will stop the
postmasters in order of PostgresNode object creation. (Perhaps we should
change that to be reverse order of creation, but the main point here is
that we now have control which we did not before.) Use "pg_ctl stop", not
an asynchronous kill(SIGQUIT), so that we wait for the postmasters to shut
down before proceeding with directory deletion.
Deletion of temporary directories still happens in an unspecified order
during global destruction, but I can see no reason to care about that
once the postmasters are stopped.
2016-04-26 18:43:03 +02:00
|
|
|
return unless defined $self->{_pid};
|
2016-01-20 18:13:11 +01:00
|
|
|
print "### Stopping node \"$name\" using mode $mode\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop');
|
|
|
|
$self->{_pid} = undef;
|
|
|
|
$self->_update_pid;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
2016-04-08 09:48:53 +02:00
|
|
|
=item $node->reload()
|
|
|
|
|
|
|
|
Reload configuration parameters on the node.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub reload
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
|
|
|
my $name = $self->name;
|
|
|
|
print "### Reloading node \"$name\"\n";
|
|
|
|
TestLib::system_log('pg_ctl', '-D', $pgdata, 'reload');
|
|
|
|
}
|
|
|
|
|
|
|
|
=pod
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=item $node->restart()
|
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
Wrapper for pg_ctl -w restart
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub restart
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
|
|
|
my $logfile = $self->logfile;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
|
|
|
print "### Restarting node \"$name\"\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-w', '-l', $logfile,
|
|
|
|
'restart');
|
|
|
|
$self->_update_pid;
|
|
|
|
}
|
|
|
|
|
2016-02-26 17:24:22 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->promote()
|
|
|
|
|
|
|
|
Wrapper for pg_ctl promote
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub promote
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $port = $self->port;
|
|
|
|
my $pgdata = $self->data_dir;
|
|
|
|
my $logfile = $self->logfile;
|
|
|
|
my $name = $self->name;
|
|
|
|
print "### Promoting node \"$name\"\n";
|
2016-03-03 17:20:46 +01:00
|
|
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile, 'promote');
|
2016-02-26 17:24:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Internal routine to enable streaming replication on a standby node.
|
|
|
|
sub enable_streaming
|
|
|
|
{
|
2016-03-03 17:20:46 +01:00
|
|
|
my ($self, $root_node) = @_;
|
2016-02-26 17:24:22 +01:00
|
|
|
my $root_connstr = $root_node->connstr;
|
2016-03-03 17:20:46 +01:00
|
|
|
my $name = $self->name;
|
2016-02-26 17:24:22 +01:00
|
|
|
|
|
|
|
print "### Enabling streaming replication for node \"$name\"\n";
|
2016-03-03 17:20:46 +01:00
|
|
|
$self->append_conf(
|
|
|
|
'recovery.conf', qq(
|
2016-02-26 17:24:22 +01:00
|
|
|
primary_conninfo='$root_connstr application_name=$name'
|
|
|
|
standby_mode=on
|
|
|
|
));
|
|
|
|
}
|
2016-02-26 01:31:52 +01:00
|
|
|
|
2016-02-26 20:13:30 +01:00
|
|
|
# Internal routine to enable archive recovery command on a standby node
|
|
|
|
sub enable_restoring
|
|
|
|
{
|
2016-03-03 17:20:46 +01:00
|
|
|
my ($self, $root_node) = @_;
|
2016-02-26 20:13:30 +01:00
|
|
|
my $path = $root_node->archive_dir;
|
|
|
|
my $name = $self->name;
|
|
|
|
|
|
|
|
print "### Enabling WAL restore for node \"$name\"\n";
|
|
|
|
|
|
|
|
# On Windows, the path specified in the restore command needs to use
|
|
|
|
# double back-slashes to work properly and to be able to detect properly
|
|
|
|
# the file targeted by the copy command, so the directory value used
|
|
|
|
# in this routine, using only one back-slash, need to be properly changed
|
|
|
|
# first. Paths also need to be double-quoted to prevent failures where
|
|
|
|
# the path contains spaces.
|
|
|
|
$path =~ s{\\}{\\\\}g if ($TestLib::windows_os);
|
2016-03-03 17:20:46 +01:00
|
|
|
my $copy_command =
|
|
|
|
$TestLib::windows_os
|
|
|
|
? qq{copy "$path\\\\%f" "%p"}
|
|
|
|
: qq{cp $path/%f %p};
|
2016-02-26 20:13:30 +01:00
|
|
|
|
2016-03-03 17:20:46 +01:00
|
|
|
$self->append_conf(
|
|
|
|
'recovery.conf', qq(
|
2016-02-26 20:13:30 +01:00
|
|
|
restore_command = '$copy_command'
|
|
|
|
standby_mode = on
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Internal routine to enable archiving
|
|
|
|
sub enable_archiving
|
|
|
|
{
|
|
|
|
my ($self) = @_;
|
|
|
|
my $path = $self->archive_dir;
|
|
|
|
my $name = $self->name;
|
|
|
|
|
|
|
|
print "### Enabling WAL archiving for node \"$name\"\n";
|
|
|
|
|
|
|
|
# On Windows, the path specified in the restore command needs to use
|
|
|
|
# double back-slashes to work properly and to be able to detect properly
|
|
|
|
# the file targeted by the copy command, so the directory value used
|
|
|
|
# in this routine, using only one back-slash, need to be properly changed
|
|
|
|
# first. Paths also need to be double-quoted to prevent failures where
|
|
|
|
# the path contains spaces.
|
|
|
|
$path =~ s{\\}{\\\\}g if ($TestLib::windows_os);
|
2016-03-03 17:20:46 +01:00
|
|
|
my $copy_command =
|
|
|
|
$TestLib::windows_os
|
|
|
|
? qq{copy "%p" "$path\\\\%f"}
|
|
|
|
: qq{cp %p $path/%f};
|
2016-02-26 20:13:30 +01:00
|
|
|
|
|
|
|
# Enable archive_mode and archive_command on node
|
2016-03-03 17:20:46 +01:00
|
|
|
$self->append_conf(
|
|
|
|
'postgresql.conf', qq(
|
2016-02-26 20:13:30 +01:00
|
|
|
archive_mode = on
|
|
|
|
archive_command = '$copy_command'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
# Internal method
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub _update_pid
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
# If we can open the PID file, read its first line and that's the PID we
|
|
|
|
# want. If the file cannot be opened, presumably the server is not
|
|
|
|
# running; don't be noisy in that case.
|
2015-12-07 23:25:31 +01:00
|
|
|
if (open my $pidfile, $self->data_dir . "/postmaster.pid")
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
2015-12-07 23:25:31 +01:00
|
|
|
chomp($self->{_pid} = <$pidfile>);
|
2016-01-20 18:13:11 +01:00
|
|
|
print "# Postmaster PID for node \"$name\" is $self->{_pid}\n";
|
2015-12-07 23:25:31 +01:00
|
|
|
close $pidfile;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-07 23:25:31 +01:00
|
|
|
$self->{_pid} = undef;
|
|
|
|
print "# No postmaster PID\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item get_new_node(node_name)
|
|
|
|
|
|
|
|
Build a new PostgresNode object, assigning a free port number. Standalone
|
|
|
|
function that's automatically imported.
|
|
|
|
|
Fix order of shutdown cleanup operations in PostgresNode.pm.
Previously, database clusters created by a TAP test were shut down by
DESTROY methods attached to the PostgresNode objects representing them.
The trouble with that is that if the objects survive into the final global
destruction phase (which they do), Perl executes the DESTROY methods in an
unspecified order. Thus, the order of shutdown of multiple clusters was
indeterminate, which might lead to not-very-reproducible errors getting
logged (eg from a slave whose master might or might not get killed first).
Worse, the File::Temp objects representing the temporary PGDATA directories
might get destroyed before the PostgresNode objects, resulting in attempts
to delete PGDATA directories that still have live servers in them. On
Windows, this would lead to directory deletion failures; on Unix, it
usually had no effects worse than erratic "could not open temporary
statistics file "pg_stat/global.tmp": No such file or directory" log
messages.
While none of this would affect the reported result of the TAP test, which
is already determined, it could be very confusing when one is trying to
understand from the logs what went wrong with a failed test.
To fix, do the postmaster shutdowns in an END block rather than at object
destruction time. The END block will execute at a well-defined (and
reasonable) time during script termination, and it will stop the
postmasters in order of PostgresNode object creation. (Perhaps we should
change that to be reverse order of creation, but the main point here is
that we now have control which we did not before.) Use "pg_ctl stop", not
an asynchronous kill(SIGQUIT), so that we wait for the postmasters to shut
down before proceeding with directory deletion.
Deletion of temporary directories still happens in an unspecified order
during global destruction, but I can see no reason to care about that
once the postmasters are stopped.
2016-04-26 18:43:03 +02:00
|
|
|
Remembers the node, to prevent its port number from being reused for another
|
|
|
|
node, and to ensure that it gets shut down when the test script exits.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
You should generally use this instead of PostgresNode::new(...).
|
|
|
|
|
|
|
|
=cut
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
sub get_new_node
|
|
|
|
{
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = shift;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $found = 0;
|
|
|
|
my $port = $last_port_assigned;
|
|
|
|
|
|
|
|
while ($found == 0)
|
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
# advance $port, wrapping correctly around range end
|
2015-12-08 00:06:21 +01:00
|
|
|
$port = 49152 if ++$port >= 65536;
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
print "# Checking port $port\n";
|
|
|
|
|
|
|
|
# Check first that candidate port number is not included in
|
|
|
|
# the list of already-registered nodes.
|
|
|
|
$found = 1;
|
|
|
|
foreach my $node (@all_nodes)
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
$found = 0 if ($node->port == $port);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check to see if anything else is listening on this TCP port.
|
|
|
|
# This is *necessary* on Windows, and seems like a good idea
|
|
|
|
# on Unixen as well, even though we don't ask the postmaster
|
|
|
|
# to open a TCP port on Unix.
|
|
|
|
if ($found == 1)
|
|
|
|
{
|
2016-04-25 18:28:49 +02:00
|
|
|
my $iaddr = inet_aton($test_localhost);
|
|
|
|
my $paddr = sockaddr_in($port, $iaddr);
|
|
|
|
my $proto = getprotobyname("tcp");
|
|
|
|
|
|
|
|
socket(SOCK, PF_INET, SOCK_STREAM, $proto)
|
|
|
|
or die "socket failed: $!";
|
|
|
|
|
|
|
|
# As in postmaster, don't use SO_REUSEADDR on Windows
|
|
|
|
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))
|
|
|
|
unless $TestLib::windows_os;
|
|
|
|
(bind(SOCK, $paddr) && listen(SOCK, SOMAXCONN))
|
|
|
|
or $found = 0;
|
Improve PostgresNode.pm's logic for detecting already-in-use ports.
Buildfarm members bowerbird and jacana have shown intermittent "could not
bind IPv4 socket" failures in the BinInstallCheck stage since mid-December,
shortly after commits 1caef31d9e550408 and 9821492ee417a591 changed the
logic for selecting which port to use in temporary installations. One
plausible explanation is that we are randomly selecting ports that are
already in use for some non-Postgres purpose. Although the code tried
to defend against already-in-use ports, it used pg_isready to probe
the port which is quite unhelpful: if some non-Postgres server responds
at the given address, pg_isready will generally say "no response",
leading to exactly the wrong conclusion about whether the port is free.
Instead, let's use a simple TCP connect() call to see if anything answers
without making assumptions about what it is. Note that this means there's
no direct check for a conflicting Unix socket, but that should be okay
because there should be no other Unix sockets in use in the temporary
socket directory created for a test run.
This is only a partial solution for the TCP case, since if the port number
is in use for an outgoing connection rather than a listening socket, we'll
fail to detect that. We could try to bind() to the proposed port as a
means of detecting that case, but that would introduce its own failure
modes, since the system might consider the address to remain reserved for
some period of time after we drop the bound socket. Close study of the
errors returned by bowerbird and jacana suggests that what we're seeing
there may be conflicts with listening not outgoing sockets, so let's try
this and see if it improves matters. It's certainly better than what's
there now, in any case.
Michael Paquier, adjusted by me to work on non-Windows as well as Windows
2016-04-24 21:31:36 +02:00
|
|
|
close(SOCK);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print "# Found free port $port\n";
|
|
|
|
|
|
|
|
# Lock port number found by creating a new node
|
2016-01-20 18:13:11 +01:00
|
|
|
my $node = new PostgresNode($name, $test_pghost, $port);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
# Add node to list of nodes
|
|
|
|
push(@all_nodes, $node);
|
|
|
|
|
|
|
|
# And update port for next time
|
|
|
|
$last_port_assigned = $port;
|
|
|
|
|
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
|
Fix order of shutdown cleanup operations in PostgresNode.pm.
Previously, database clusters created by a TAP test were shut down by
DESTROY methods attached to the PostgresNode objects representing them.
The trouble with that is that if the objects survive into the final global
destruction phase (which they do), Perl executes the DESTROY methods in an
unspecified order. Thus, the order of shutdown of multiple clusters was
indeterminate, which might lead to not-very-reproducible errors getting
logged (eg from a slave whose master might or might not get killed first).
Worse, the File::Temp objects representing the temporary PGDATA directories
might get destroyed before the PostgresNode objects, resulting in attempts
to delete PGDATA directories that still have live servers in them. On
Windows, this would lead to directory deletion failures; on Unix, it
usually had no effects worse than erratic "could not open temporary
statistics file "pg_stat/global.tmp": No such file or directory" log
messages.
While none of this would affect the reported result of the TAP test, which
is already determined, it could be very confusing when one is trying to
understand from the logs what went wrong with a failed test.
To fix, do the postmaster shutdowns in an END block rather than at object
destruction time. The END block will execute at a well-defined (and
reasonable) time during script termination, and it will stop the
postmasters in order of PostgresNode object creation. (Perhaps we should
change that to be reverse order of creation, but the main point here is
that we now have control which we did not before.) Use "pg_ctl stop", not
an asynchronous kill(SIGQUIT), so that we wait for the postmasters to shut
down before proceeding with directory deletion.
Deletion of temporary directories still happens in an unspecified order
during global destruction, but I can see no reason to care about that
once the postmasters are stopped.
2016-04-26 18:43:03 +02:00
|
|
|
# Automatically shut down any still-running nodes when the test script exits.
|
|
|
|
# Note that this just stops the postmasters (in the same order the nodes were
|
|
|
|
# created in). Temporary PGDATA directories are deleted, in an unspecified
|
|
|
|
# order, later when the File::Temp objects are destroyed.
|
|
|
|
END
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
Fix order of shutdown cleanup operations in PostgresNode.pm.
Previously, database clusters created by a TAP test were shut down by
DESTROY methods attached to the PostgresNode objects representing them.
The trouble with that is that if the objects survive into the final global
destruction phase (which they do), Perl executes the DESTROY methods in an
unspecified order. Thus, the order of shutdown of multiple clusters was
indeterminate, which might lead to not-very-reproducible errors getting
logged (eg from a slave whose master might or might not get killed first).
Worse, the File::Temp objects representing the temporary PGDATA directories
might get destroyed before the PostgresNode objects, resulting in attempts
to delete PGDATA directories that still have live servers in them. On
Windows, this would lead to directory deletion failures; on Unix, it
usually had no effects worse than erratic "could not open temporary
statistics file "pg_stat/global.tmp": No such file or directory" log
messages.
While none of this would affect the reported result of the TAP test, which
is already determined, it could be very confusing when one is trying to
understand from the logs what went wrong with a failed test.
To fix, do the postmaster shutdowns in an END block rather than at object
destruction time. The END block will execute at a well-defined (and
reasonable) time during script termination, and it will stop the
postmasters in order of PostgresNode object creation. (Perhaps we should
change that to be reverse order of creation, but the main point here is
that we now have control which we did not before.) Use "pg_ctl stop", not
an asynchronous kill(SIGQUIT), so that we wait for the postmasters to shut
down before proceeding with directory deletion.
Deletion of temporary directories still happens in an unspecified order
during global destruction, but I can see no reason to care about that
once the postmasters are stopped.
2016-04-26 18:43:03 +02:00
|
|
|
# take care not to change the script's exit value
|
|
|
|
my $exit_code = $?;
|
|
|
|
|
|
|
|
foreach my $node (@all_nodes)
|
|
|
|
{
|
|
|
|
$node->teardown_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
$? = $exit_code;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->teardown_node()
|
|
|
|
|
|
|
|
Do an immediate stop of the node
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub teardown_node
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->stop('immediate');
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
=item $node->safe_psql($dbname, $sql) => stdout
|
2016-02-26 01:31:52 +01:00
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
Invoke B<psql> to run B<sql> on B<dbname> and return its stdout on success.
|
|
|
|
Die if the SQL produces an error. Runs with B<ON_ERROR_STOP> set.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
Takes optional extra params like timeout and timed_out parameters with the same
|
|
|
|
options as psql.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
sub safe_psql
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
{
|
2016-03-03 21:58:30 +01:00
|
|
|
my ($self, $dbname, $sql, %params) = @_;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
my $ret = $self->psql(
|
|
|
|
$dbname, $sql,
|
|
|
|
%params,
|
|
|
|
stdout => \$stdout,
|
|
|
|
stderr => \$stderr,
|
|
|
|
on_error_die => 1,
|
|
|
|
on_error_stop => 1);
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
# psql can emit stderr from NOTICEs etc
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
if ($stderr ne "")
|
|
|
|
{
|
|
|
|
print "#### Begin standard error\n";
|
|
|
|
print $stderr;
|
2016-03-03 21:58:30 +01:00
|
|
|
print "\n#### End standard error\n";
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
}
|
2016-03-03 21:58:30 +01:00
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
return $stdout;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
=item $node->psql($dbname, $sql, %params) => psql_retval
|
|
|
|
|
|
|
|
Invoke B<psql> to execute B<$sql> on B<$dbname> and return the return value
|
|
|
|
from B<psql>, which is run with on_error_stop by default so that it will
|
|
|
|
stop running sql and return 3 if the passed SQL results in an error.
|
|
|
|
|
|
|
|
As a convenience, if B<psql> is called in array context it returns an
|
|
|
|
array containing ($retval, $stdout, $stderr).
|
|
|
|
|
|
|
|
psql is invoked in tuples-only unaligned mode with reading of B<.psqlrc>
|
|
|
|
disabled. That may be overridden by passing extra psql parameters.
|
|
|
|
|
|
|
|
stdout and stderr are transformed to UNIX line endings if on Windows. Any
|
|
|
|
trailing newline is removed.
|
|
|
|
|
|
|
|
Dies on failure to invoke psql but not if psql exits with a nonzero
|
|
|
|
return code (unless on_error_die specified).
|
|
|
|
|
|
|
|
If psql exits because of a signal, an exception is raised.
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item stdout => \$stdout
|
|
|
|
|
|
|
|
B<stdout>, if given, must be a scalar reference to which standard output is
|
|
|
|
written. If not given, standard output is not redirected and will be printed
|
|
|
|
unless B<psql> is called in array context, in which case it's captured and
|
|
|
|
returned.
|
|
|
|
|
|
|
|
=item stderr => \$stderr
|
|
|
|
|
|
|
|
Same as B<stdout> but gets standard error. If the same scalar is passed for
|
|
|
|
both B<stdout> and B<stderr> the results may be interleaved unpredictably.
|
|
|
|
|
|
|
|
=item on_error_stop => 1
|
|
|
|
|
|
|
|
By default, the B<psql> method invokes the B<psql> program with ON_ERROR_STOP=1
|
|
|
|
set, so SQL execution is stopped at the first error and exit code 2 is
|
|
|
|
returned. Set B<on_error_stop> to 0 to ignore errors instead.
|
|
|
|
|
|
|
|
=item on_error_die => 0
|
|
|
|
|
|
|
|
By default, this method returns psql's result code. Pass on_error_die to
|
|
|
|
instead die with an informative message.
|
|
|
|
|
|
|
|
=item timeout => 'interval'
|
|
|
|
|
|
|
|
Set a timeout for the psql call as an interval accepted by B<IPC::Run::timer>
|
|
|
|
(integer seconds is fine). This method raises an exception on timeout, unless
|
|
|
|
the B<timed_out> parameter is also given.
|
|
|
|
|
|
|
|
=item timed_out => \$timed_out
|
|
|
|
|
|
|
|
If B<timeout> is set and this parameter is given, the scalar it references
|
|
|
|
is set to true if the psql call times out.
|
|
|
|
|
|
|
|
=item extra_params => ['--single-transaction']
|
|
|
|
|
|
|
|
If given, it must be an array reference containing additional parameters to B<psql>.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
e.g.
|
|
|
|
|
|
|
|
my ($stdout, $stderr, $timed_out);
|
|
|
|
my $cmdret = $node->psql('postgres', 'SELECT pg_sleep(60)',
|
|
|
|
stdout => \$stdout, stderr => \$stderr,
|
|
|
|
timeout => 30, timed_out => \$timed_out,
|
|
|
|
extra_params => ['--single-transaction'])
|
|
|
|
|
|
|
|
will set $cmdret to undef and $timed_out to a true value.
|
|
|
|
|
|
|
|
$node->psql('postgres', $sql, on_error_die => 1);
|
|
|
|
|
|
|
|
dies with an informative message if $sql fails.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub psql
|
|
|
|
{
|
|
|
|
my ($self, $dbname, $sql, %params) = @_;
|
|
|
|
|
|
|
|
my $stdout = $params{stdout};
|
|
|
|
my $stderr = $params{stderr};
|
|
|
|
my $timeout = undef;
|
|
|
|
my $timeout_exception = 'psql timed out';
|
|
|
|
my @psql_params =
|
|
|
|
('psql', '-XAtq', '-d', $self->connstr($dbname), '-f', '-');
|
|
|
|
|
|
|
|
# If the caller wants an array and hasn't passed stdout/stderr
|
|
|
|
# references, allocate temporary ones to capture them so we
|
|
|
|
# can return them. Otherwise we won't redirect them at all.
|
|
|
|
if (wantarray)
|
|
|
|
{
|
|
|
|
if (!defined($stdout))
|
|
|
|
{
|
|
|
|
my $temp_stdout = "";
|
|
|
|
$stdout = \$temp_stdout;
|
|
|
|
}
|
|
|
|
if (!defined($stderr))
|
|
|
|
{
|
|
|
|
my $temp_stderr = "";
|
|
|
|
$stderr = \$temp_stderr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$params{on_error_stop} = 1 unless defined $params{on_error_stop};
|
|
|
|
$params{on_error_die} = 0 unless defined $params{on_error_die};
|
|
|
|
|
|
|
|
push @psql_params, '-v', 'ON_ERROR_STOP=1' if $params{on_error_stop};
|
|
|
|
push @psql_params, @{ $params{extra_params} }
|
|
|
|
if defined $params{extra_params};
|
|
|
|
|
|
|
|
$timeout =
|
|
|
|
IPC::Run::timeout($params{timeout}, exception => $timeout_exception)
|
|
|
|
if (defined($params{timeout}));
|
|
|
|
|
2016-06-12 10:19:56 +02:00
|
|
|
${ $params{timed_out} } = 0 if defined $params{timed_out};
|
2016-03-29 00:17:06 +02:00
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
# IPC::Run would otherwise append to existing contents:
|
|
|
|
$$stdout = "" if ref($stdout);
|
|
|
|
$$stderr = "" if ref($stderr);
|
|
|
|
|
|
|
|
my $ret;
|
|
|
|
|
|
|
|
# Run psql and capture any possible exceptions. If the exception is
|
|
|
|
# because of a timeout and the caller requested to handle that, just return
|
|
|
|
# and set the flag. Otherwise, and for any other exception, rethrow.
|
|
|
|
#
|
|
|
|
# For background, see
|
|
|
|
# http://search.cpan.org/~ether/Try-Tiny-0.24/lib/Try/Tiny.pm
|
|
|
|
do
|
|
|
|
{
|
|
|
|
local $@;
|
|
|
|
eval {
|
|
|
|
my @ipcrun_opts = (\@psql_params, '<', \$sql);
|
|
|
|
push @ipcrun_opts, '>', $stdout if defined $stdout;
|
|
|
|
push @ipcrun_opts, '2>', $stderr if defined $stderr;
|
|
|
|
push @ipcrun_opts, $timeout if defined $timeout;
|
|
|
|
|
|
|
|
IPC::Run::run @ipcrun_opts;
|
|
|
|
$ret = $?;
|
|
|
|
};
|
|
|
|
my $exc_save = $@;
|
|
|
|
if ($exc_save)
|
|
|
|
{
|
2016-06-12 10:19:56 +02:00
|
|
|
|
2016-03-03 21:58:30 +01:00
|
|
|
# IPC::Run::run threw an exception. re-throw unless it's a
|
|
|
|
# timeout, which we'll handle by testing is_expired
|
|
|
|
die $exc_save
|
|
|
|
if (blessed($exc_save) || $exc_save ne $timeout_exception);
|
|
|
|
|
|
|
|
$ret = undef;
|
|
|
|
|
|
|
|
die "Got timeout exception '$exc_save' but timer not expired?!"
|
|
|
|
unless $timeout->is_expired;
|
|
|
|
|
|
|
|
if (defined($params{timed_out}))
|
|
|
|
{
|
|
|
|
${ $params{timed_out} } = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "psql timed out: stderr: '$$stderr'\n"
|
|
|
|
. "while running '@psql_params'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (defined $$stdout)
|
|
|
|
{
|
|
|
|
chomp $$stdout;
|
|
|
|
$$stdout =~ s/\r//g if $TestLib::windows_os;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $$stderr)
|
|
|
|
{
|
|
|
|
chomp $$stderr;
|
|
|
|
$$stderr =~ s/\r//g if $TestLib::windows_os;
|
|
|
|
}
|
|
|
|
|
|
|
|
# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
|
|
|
|
# We don't use IPC::Run::Simple to limit dependencies.
|
|
|
|
#
|
|
|
|
# We always die on signal.
|
|
|
|
my $core = $ret & 128 ? " (core dumped)" : "";
|
|
|
|
die "psql exited with signal "
|
|
|
|
. ($ret & 127)
|
|
|
|
. "$core: '$$stderr' while running '@psql_params'"
|
|
|
|
if $ret & 127;
|
|
|
|
$ret = $ret >> 8;
|
|
|
|
|
|
|
|
if ($ret && $params{on_error_die})
|
|
|
|
{
|
|
|
|
die "psql error: stderr: '$$stderr'\nwhile running '@psql_params'"
|
|
|
|
if $ret == 1;
|
|
|
|
die "connection error: '$$stderr'\nwhile running '@psql_params'"
|
|
|
|
if $ret == 2;
|
|
|
|
die "error running SQL: '$$stderr'\nwhile running '@psql_params'"
|
|
|
|
if $ret == 3;
|
|
|
|
die "psql returns $ret: '$$stderr'\nwhile running '@psql_params'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wantarray)
|
|
|
|
{
|
|
|
|
return ($ret, $$stdout, $$stderr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
=pod
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=item $node->poll_query_until(dbname, query)
|
|
|
|
|
|
|
|
Run a query once a second, until it returns 't' (i.e. SQL boolean true).
|
|
|
|
Continues polling if psql returns an error result. Times out after 90 seconds.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub poll_query_until
|
|
|
|
{
|
|
|
|
my ($self, $dbname, $query) = @_;
|
|
|
|
|
2016-02-11 02:34:57 +01:00
|
|
|
my $max_attempts = 90;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $attempts = 0;
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
|
|
|
|
while ($attempts < $max_attempts)
|
|
|
|
{
|
|
|
|
my $cmd =
|
2015-12-08 20:04:08 +01:00
|
|
|
[ 'psql', '-XAt', '-c', $query, '-d', $self->connstr($dbname) ];
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
|
|
|
|
|
|
|
|
chomp($stdout);
|
2016-03-03 21:58:30 +01:00
|
|
|
$stdout =~ s/\r//g if $TestLib::windows_os;
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
if ($stdout eq "t")
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Wait a second before retrying.
|
|
|
|
sleep 1;
|
|
|
|
$attempts++;
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:34:57 +01:00
|
|
|
# The query result didn't change in 90 seconds. Give up. Print the stderr
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
# from the last attempt, hopefully that's useful for debugging.
|
|
|
|
diag $stderr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->command_ok(...)
|
|
|
|
|
|
|
|
Runs a shell command like TestLib::command_ok, but with PGPORT
|
|
|
|
set so that the command will default to connecting to this
|
|
|
|
PostgresNode.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub command_ok
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
local $ENV{PGPORT} = $self->port;
|
|
|
|
|
|
|
|
TestLib::command_ok(@_);
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->command_fails(...) - TestLib::command_fails with our PGPORT
|
|
|
|
|
|
|
|
See command_ok(...)
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub command_fails
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
local $ENV{PGPORT} = $self->port;
|
|
|
|
|
|
|
|
TestLib::command_fails(@_);
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->command_like(...)
|
|
|
|
|
|
|
|
TestLib::command_like with our PGPORT. See command_ok(...)
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub command_like
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
local $ENV{PGPORT} = $self->port;
|
|
|
|
|
|
|
|
TestLib::command_like(@_);
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=item $node->issues_sql_like(cmd, expected_sql, test_name)
|
|
|
|
|
|
|
|
Run a command on the node, then verify that $expected_sql appears in the
|
|
|
|
server log file.
|
|
|
|
|
|
|
|
Reads the whole log file so be careful when working with large log outputs.
|
2016-02-26 17:24:22 +01:00
|
|
|
The log file is truncated prior to running the command, however.
|
2016-02-26 01:31:52 +01:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
sub issues_sql_like
|
|
|
|
{
|
|
|
|
my ($self, $cmd, $expected_sql, $test_name) = @_;
|
|
|
|
|
|
|
|
local $ENV{PGPORT} = $self->port;
|
|
|
|
|
|
|
|
truncate $self->logfile, 0;
|
|
|
|
my $result = TestLib::run_log($cmd);
|
|
|
|
ok($result, "@$cmd exit code 0");
|
|
|
|
my $log = TestLib::slurp_file($self->logfile);
|
|
|
|
like($log, $expected_sql, "$test_name: SQL found in server log");
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
|
|
|
1;
|