Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3377497

Browse files
Avoid using internal test methods in SSL tests
The SSL tests for pg_ctl restart with an incorrect key passphrase used the internal _update_pid method to set the pidfile after running pg_ctl manually instead of using the supplied ->restart method. This refactors the ->restart method to accept a fail_ok parameter like how ->start and ->stop does, and changes the SSL tests to use this instead. This removes the need to call internal test module functions. Reviewed-by: Melih Mutlu <m.melihmutlu@gmail.com> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/F81643C4-D7B8-4C6B-AF18-B73839966279@yesql.se
1 parent 5f3aa30 commit 3377497

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

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

+23-8
Original file line numberDiff line numberDiff line change
@@ -1035,29 +1035,44 @@ sub reload
10351035
10361036
=item $node->restart()
10371037
1038-
Wrapper for pg_ctl restart
1038+
Wrapper for pg_ctl restart.
1039+
1040+
With optional extra param fail_ok => 1, returns 0 for failure
1041+
instead of bailing out.
10391042
10401043
=cut
10411044

10421045
sub restart
10431046
{
1044-
my ($self) = @_;
1045-
my $port = $self->port;
1046-
my $pgdata = $self->data_dir;
1047-
my $logfile = $self->logfile;
1047+
my ($self, %params) = @_;
10481048
my $name = $self->name;
1049+
my $ret;
10491050

10501051
local %ENV = $self->_get_env(PGAPPNAME => undef);
10511052

10521053
print "### Restarting node \"$name\"\n";
10531054

10541055
# -w is now the default but having it here does no harm and helps
10551056
# compatibility with older versions.
1056-
PostgreSQL::Test::Utils::system_or_bail('pg_ctl', '-w', '-D', $pgdata,
1057-
'-l', $logfile, 'restart');
1057+
$ret = PostgreSQL::Test::Utils::system_log(
1058+
'pg_ctl', '-w', '-D', $self->data_dir,
1059+
'-l', $self->logfile, 'restart');
1060+
1061+
if ($ret != 0)
1062+
{
1063+
print "# pg_ctl restart failed; logfile:\n";
1064+
print PostgreSQL::Test::Utils::slurp_file($self->logfile);
1065+
1066+
# pg_ctl could have timed out, so check to see if there's a pid file;
1067+
# otherwise our END block will fail to shut down the new postmaster.
1068+
$self->_update_pid(-1);
1069+
1070+
BAIL_OUT("pg_ctl restart failed") unless $params{fail_ok};
1071+
return 0;
1072+
}
10581073

10591074
$self->_update_pid(1);
1060-
return;
1075+
return 1;
10611076
}
10621077

10631078
=pod

src/test/ssl/t/001_ssltests.pl

+9-14
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ sub switch_server_cert
8585
passphrase_cmd => 'echo wrongpassword',
8686
restart => 'no');
8787

88-
command_fails(
89-
[ 'pg_ctl', '-D', $node->data_dir, '-l', $node->logfile, 'restart' ],
90-
'restart fails with password-protected key file with wrong password');
91-
$node->_update_pid(0);
88+
$result = $node->restart(fail_ok => 1);
89+
is($result, 0, 'restart fails with password-protected key file with wrong password');
9290

9391
switch_server_cert(
9492
$node,
@@ -98,28 +96,25 @@ sub switch_server_cert
9896
passphrase_cmd => 'echo secret1',
9997
restart => 'no');
10098

101-
command_ok(
102-
[ 'pg_ctl', '-D', $node->data_dir, '-l', $node->logfile, 'restart' ],
103-
'restart succeeds with password-protected key file');
104-
$node->_update_pid(1);
99+
$result = $node->restart(fail_ok => 1);
100+
is($result, 1, 'restart succeeds with password-protected key file');
105101

106102
# Test compatibility of SSL protocols.
107103
# TLSv1.1 is lower than TLSv1.2, so it won't work.
108104
$node->append_conf(
109105
'postgresql.conf',
110106
qq{ssl_min_protocol_version='TLSv1.2'
111107
ssl_max_protocol_version='TLSv1.1'});
112-
command_fails(
113-
[ 'pg_ctl', '-D', $node->data_dir, '-l', $node->logfile, 'restart' ],
114-
'restart fails with incorrect SSL protocol bounds');
108+
$result = $node->restart(fail_ok => 1);
109+
is($result, 0, 'restart fails with incorrect SSL protocol bounds');
110+
115111
# Go back to the defaults, this works.
116112
$node->append_conf(
117113
'postgresql.conf',
118114
qq{ssl_min_protocol_version='TLSv1.2'
119115
ssl_max_protocol_version=''});
120-
command_ok(
121-
[ 'pg_ctl', '-D', $node->data_dir, '-l', $node->logfile, 'restart' ],
122-
'restart succeeds with correct SSL protocol bounds');
116+
$result = $node->restart(fail_ok => 1);
117+
is($result, 1, 'restart succeeds with correct SSL protocol bounds');
123118

124119
### Run client-side tests.
125120
###

0 commit comments

Comments
 (0)