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');
|
|
|
|
|
|
|
|
# run a query with psql
|
|
|
|
# like: psql -qAXt postgres -c 'SELECT 1;'
|
|
|
|
$psql_stdout = $node->psql('postgres', 'SELECT 1');
|
|
|
|
|
|
|
|
# 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
|
|
|
|
my $ret = $node->backup('testbackup');
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
use Test::More;
|
|
|
|
use TestLib ();
|
|
|
|
|
|
|
|
our @EXPORT = qw(
|
|
|
|
get_new_node
|
|
|
|
);
|
|
|
|
|
|
|
|
our ($test_pghost, $last_port_assigned, @all_nodes);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
# PGHOST is set once and for all through a single series of tests when
|
|
|
|
# this module is loaded.
|
|
|
|
$test_pghost =
|
|
|
|
$TestLib::windows_os ? "127.0.0.1" : TestLib::tempdir_short;
|
|
|
|
$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
|
|
|
|
{
|
|
|
|
my $class = shift;
|
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 $pghost = shift;
|
|
|
|
my $pgport = shift;
|
2015-12-07 23:25:31 +01:00
|
|
|
my $testname = basename($0);
|
|
|
|
$testname =~ s/\.[^.]+$//;
|
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 = {
|
|
|
|
_port => $pgport,
|
|
|
|
_host => $pghost,
|
|
|
|
_basedir => TestLib::tempdir,
|
2016-01-20 18:13:11 +01:00
|
|
|
_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
|
|
|
|
"host replication all 127.0.0.1/32 sspi include_realm=1 map=regress\n";
|
|
|
|
}
|
|
|
|
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-02-26 20:13:30 +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})
|
|
|
|
{
|
|
|
|
print $conf "wal_level = hot_standby\n";
|
|
|
|
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-02-26 20:13:30 +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)
|
|
|
|
|
|
|
|
Create a hot backup with pg_basebackup in $node->backup_dir,
|
|
|
|
including the transaction logs. xlogs are fetched at the
|
|
|
|
end of the backup, not streamed.
|
|
|
|
|
|
|
|
You'll have to configure a suitable max_wal_senders on the
|
|
|
|
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-01-20 18:13:11 +01:00
|
|
|
print "# Taking backup $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-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
|
|
|
|
by passiong the keyword parameter has_restoring => 1. This is disabled by
|
|
|
|
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
|
|
|
|
unless defined $params{hba_permit_replication};
|
|
|
|
$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-02-26 20:13:30 +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;
|
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
|
|
|
|
|
|
|
|
=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";
|
|
|
|
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile,
|
|
|
|
'promote');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Internal routine to enable streaming replication on a standby node.
|
|
|
|
sub enable_streaming
|
|
|
|
{
|
|
|
|
my ($self, $root_node) = @_;
|
|
|
|
my $root_connstr = $root_node->connstr;
|
|
|
|
my $name = $self->name;
|
|
|
|
|
|
|
|
print "### Enabling streaming replication for node \"$name\"\n";
|
|
|
|
$self->append_conf('recovery.conf', qq(
|
|
|
|
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
|
|
|
|
{
|
|
|
|
my ($self, $root_node) = @_;
|
|
|
|
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);
|
|
|
|
my $copy_command = $TestLib::windows_os ?
|
|
|
|
qq{copy "$path\\\\%f" "%p"} :
|
|
|
|
qq{cp $path/%f %p};
|
|
|
|
|
|
|
|
$self->append_conf('recovery.conf', qq(
|
|
|
|
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);
|
|
|
|
my $copy_command = $TestLib::windows_os ?
|
|
|
|
qq{copy "%p" "$path\\\\%f"} :
|
|
|
|
qq{cp %p $path/%f};
|
|
|
|
|
|
|
|
# Enable archive_mode and archive_command on node
|
|
|
|
$self->append_conf('postgresql.conf', qq(
|
|
|
|
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.
|
|
|
|
|
|
|
|
We also register the node, to avoid the port number from being reused
|
|
|
|
for another node even when this one is not active.
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-12-08 00:06:21 +01:00
|
|
|
# wrap correctly around range end
|
|
|
|
$port = 49152 if ++$port >= 65536;
|
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 "# Checking for port $port\n";
|
|
|
|
if (!TestLib::run_log([ 'pg_isready', '-p', $port ]))
|
|
|
|
{
|
|
|
|
$found = 1;
|
|
|
|
|
|
|
|
# Found a potential candidate port number. Check first that it is
|
|
|
|
# not included in the list of registered nodes.
|
|
|
|
foreach my $node (@all_nodes)
|
|
|
|
{
|
|
|
|
$found = 0 if ($node->port == $port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
# Attempt automatic cleanup
|
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 DESTROY
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
2016-02-26 17:24:22 +01:00
|
|
|
return unless defined $self->{_pid};
|
2016-01-20 18:13:11 +01:00
|
|
|
print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n";
|
2015-12-07 23:25:31 +01:00
|
|
|
TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
=item $node->psql(dbname, sql)
|
|
|
|
|
|
|
|
Run a query with psql and return stdout, or on error print stderr.
|
|
|
|
|
|
|
|
Executes a query/script with psql and returns psql's standard output. psql is
|
|
|
|
run in unaligned tuples-only quiet mode with psqlrc disabled so simple queries
|
|
|
|
will just return the result row(s) with fields separated by commas.
|
|
|
|
|
|
|
|
=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 psql
|
|
|
|
{
|
|
|
|
my ($self, $dbname, $sql) = @_;
|
|
|
|
|
|
|
|
my ($stdout, $stderr);
|
2016-01-20 18:13:11 +01:00
|
|
|
my $name = $self->name;
|
|
|
|
print("### Running SQL command on node \"$name\": $sql\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
|
|
|
|
|
|
|
IPC::Run::run [ 'psql', '-XAtq', '-d', $self->connstr($dbname), '-f',
|
|
|
|
'-' ], '<', \$sql, '>', \$stdout, '2>', \$stderr
|
|
|
|
or die;
|
|
|
|
|
|
|
|
if ($stderr ne "")
|
|
|
|
{
|
|
|
|
print "#### Begin standard error\n";
|
|
|
|
print $stderr;
|
|
|
|
print "#### End standard error\n";
|
|
|
|
}
|
|
|
|
chomp $stdout;
|
|
|
|
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
|
|
|
|
return $stdout;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:31:52 +01:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=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);
|
|
|
|
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
|
|
|
|
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;
|