perltidy PostgresNode and SimpleTee

Also, mention in README that Perl files should be perltidy'ed.  This
isn't really the best place (since we have Perl files elsewhere in the
tree) and this is already in pgindent's README, but this subdir is
likely to get hacked a whole lot more than the other Perl files, so it
seems okay to spend two lines on this.

Author: Craig Ringer
This commit is contained in:
Alvaro Herrera 2016-03-03 13:20:46 -03:00
parent 5bec1ad464
commit 7d9a4301c0
3 changed files with 41 additions and 33 deletions

View File

@ -1,3 +1,4 @@
=pod =pod
=head1 NAME =head1 NAME
@ -106,18 +107,15 @@ of finding port numbers, registering instances for cleanup, etc.
sub new sub new
{ {
my $class = shift; my ($class, $name, $pghost, $pgport) = @_;
my $name = shift;
my $pghost = shift;
my $pgport = shift;
my $testname = basename($0); my $testname = basename($0);
$testname =~ s/\.[^.]+$//; $testname =~ s/\.[^.]+$//;
my $self = { my $self = {
_port => $pgport, _port => $pgport,
_host => $pghost, _host => $pghost,
_basedir => TestLib::tempdir("data_" . $name), _basedir => TestLib::tempdir("data_" . $name),
_name => $name, _name => $name,
_logfile => "$TestLib::log_path/${testname}_${name}.log" }; _logfile => "$TestLib::log_path/${testname}_${name}.log" };
bless $self, $class; bless $self, $class;
$self->dump_info; $self->dump_info;
@ -367,7 +365,7 @@ sub init
$params{hba_permit_replication} = 1 $params{hba_permit_replication} = 1
unless defined $params{hba_permit_replication}; unless defined $params{hba_permit_replication};
$params{allows_streaming} = 0 unless defined $params{allows_streaming}; $params{allows_streaming} = 0 unless defined $params{allows_streaming};
$params{has_archiving} = 0 unless defined $params{has_archiving}; $params{has_archiving} = 0 unless defined $params{has_archiving};
mkdir $self->backup_dir; mkdir $self->backup_dir;
mkdir $self->archive_dir; mkdir $self->archive_dir;
@ -405,7 +403,7 @@ sub init
close $conf; close $conf;
$self->set_replication_conf if $params{hba_permit_replication}; $self->set_replication_conf if $params{hba_permit_replication};
$self->enable_archiving if $params{has_archiving}; $self->enable_archiving if $params{has_archiving};
} }
=pod =pod
@ -492,7 +490,7 @@ sub init_from_backup
$params{has_streaming} = 0 unless defined $params{has_streaming}; $params{has_streaming} = 0 unless defined $params{has_streaming};
$params{hba_permit_replication} = 1 $params{hba_permit_replication} = 1
unless defined $params{hba_permit_replication}; unless defined $params{hba_permit_replication};
$params{has_restoring} = 0 unless defined $params{has_restoring}; $params{has_restoring} = 0 unless defined $params{has_restoring};
print print
@ -514,7 +512,7 @@ sub init_from_backup
qq( qq(
port = $port port = $port
)); ));
$self->set_replication_conf if $params{hba_permit_replication}; $self->set_replication_conf if $params{hba_permit_replication};
$self->enable_streaming($root_node) if $params{has_streaming}; $self->enable_streaming($root_node) if $params{has_streaming};
$self->enable_restoring($root_node) if $params{has_restoring}; $self->enable_restoring($root_node) if $params{has_restoring};
} }
@ -607,19 +605,19 @@ sub promote
my $logfile = $self->logfile; my $logfile = $self->logfile;
my $name = $self->name; my $name = $self->name;
print "### Promoting node \"$name\"\n"; print "### Promoting node \"$name\"\n";
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile, TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile, 'promote');
'promote');
} }
# Internal routine to enable streaming replication on a standby node. # Internal routine to enable streaming replication on a standby node.
sub enable_streaming sub enable_streaming
{ {
my ($self, $root_node) = @_; my ($self, $root_node) = @_;
my $root_connstr = $root_node->connstr; my $root_connstr = $root_node->connstr;
my $name = $self->name; my $name = $self->name;
print "### Enabling streaming replication for node \"$name\"\n"; print "### Enabling streaming replication for node \"$name\"\n";
$self->append_conf('recovery.conf', qq( $self->append_conf(
'recovery.conf', qq(
primary_conninfo='$root_connstr application_name=$name' primary_conninfo='$root_connstr application_name=$name'
standby_mode=on standby_mode=on
)); ));
@ -628,7 +626,7 @@ standby_mode=on
# Internal routine to enable archive recovery command on a standby node # Internal routine to enable archive recovery command on a standby node
sub enable_restoring sub enable_restoring
{ {
my ($self, $root_node) = @_; my ($self, $root_node) = @_;
my $path = $root_node->archive_dir; my $path = $root_node->archive_dir;
my $name = $self->name; my $name = $self->name;
@ -641,11 +639,13 @@ sub enable_restoring
# first. Paths also need to be double-quoted to prevent failures where # first. Paths also need to be double-quoted to prevent failures where
# the path contains spaces. # the path contains spaces.
$path =~ s{\\}{\\\\}g if ($TestLib::windows_os); $path =~ s{\\}{\\\\}g if ($TestLib::windows_os);
my $copy_command = $TestLib::windows_os ? my $copy_command =
qq{copy "$path\\\\%f" "%p"} : $TestLib::windows_os
qq{cp $path/%f %p}; ? qq{copy "$path\\\\%f" "%p"}
: qq{cp $path/%f %p};
$self->append_conf('recovery.conf', qq( $self->append_conf(
'recovery.conf', qq(
restore_command = '$copy_command' restore_command = '$copy_command'
standby_mode = on standby_mode = on
)); ));
@ -667,12 +667,14 @@ sub enable_archiving
# first. Paths also need to be double-quoted to prevent failures where # first. Paths also need to be double-quoted to prevent failures where
# the path contains spaces. # the path contains spaces.
$path =~ s{\\}{\\\\}g if ($TestLib::windows_os); $path =~ s{\\}{\\\\}g if ($TestLib::windows_os);
my $copy_command = $TestLib::windows_os ? my $copy_command =
qq{copy "%p" "$path\\\\%f"} : $TestLib::windows_os
qq{cp %p $path/%f}; ? qq{copy "%p" "$path\\\\%f"}
: qq{cp %p $path/%f};
# Enable archive_mode and archive_command on node # Enable archive_mode and archive_command on node
$self->append_conf('postgresql.conf', qq( $self->append_conf(
'postgresql.conf', qq(
archive_mode = on archive_mode = on
archive_command = '$copy_command' archive_command = '$copy_command'
)); ));

View File

@ -11,6 +11,9 @@ isolation tester specs in src/test/isolation, if possible. If not, check to
see if your new tests make sense under an existing tree in src/test, like see if your new tests make sense under an existing tree in src/test, like
src/test/ssl, or should be added to one of the suites for an existing utility. src/test/ssl, or should be added to one of the suites for an existing utility.
Note that all tests and test tools should have perltidy run on them before
patches are submitted, using perltidy --profile=src/tools/pgindent/perltidyrc
Writing tests Writing tests
------------- -------------

View File

@ -10,17 +10,20 @@
package SimpleTee; package SimpleTee;
use strict; use strict;
sub TIEHANDLE { sub TIEHANDLE
{
my $self = shift; my $self = shift;
bless \@_, $self; bless \@_, $self;
} }
sub PRINT { sub PRINT
{
my $self = shift; my $self = shift;
my $ok = 1; my $ok = 1;
for my $fh (@$self) { for my $fh (@$self)
{
print $fh @_ or $ok = 0; print $fh @_ or $ok = 0;
$fh->flush or $ok = 0; $fh->flush or $ok = 0;
} }
return $ok; return $ok;
} }