Skip to content

Commit 3769e11

Browse files
committed
Make test_target_session_attrs more robust against connection failure.
Feed the desired command to psql via "-c" not stdin, else Perl may complain that it can't push stdin to an already-failed psql process, as seen in intermittent buildfarm failures. Make some minor cosmetic improvements while at it. Before commit ee28cac we had no tests here that expected failure to connect, so there seems no need for a back-patch. Discussion: https://postgr.es/m/CALDaNm2mo8YED=M2ZJKGf1U3F3mw6SaQuLXWCK8rZP6sECYcrA@mail.gmail.com
1 parent f06b1c5 commit 3769e11

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/test/recovery/t/001_stream_rep.pl

+14-11
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
# Tests for connection parameter target_session_attrs
6969
note "testing connection parameter \"target_session_attrs\"";
7070

71-
# Routine designed to run tests on the connection parameter
72-
# target_session_attrs with multiple nodes.
71+
# Attempt to connect to $node1, then $node2, using target_session_attrs=$mode.
72+
# Expect to connect to $target_node (undef for failure) with given $status.
7373
sub test_target_session_attrs
7474
{
7575
my $node1 = shift;
@@ -84,7 +84,8 @@ sub test_target_session_attrs
8484
my $node2_host = $node2->host;
8585
my $node2_port = $node2->port;
8686
my $node2_name = $node2->name;
87-
87+
my $target_port = undef;
88+
$target_port = $target_node->port if (defined $target_node);
8889
my $target_name = undef;
8990
$target_name = $target_node->name if (defined $target_node);
9091

@@ -93,16 +94,18 @@ sub test_target_session_attrs
9394
$connstr .= "port=$node1_port,$node2_port ";
9495
$connstr .= "target_session_attrs=$mode";
9596

96-
# The client used for the connection does not matter, only the backend
97-
# point does.
97+
# Attempt to connect, and if successful, get the server port number
98+
# we connected to. Note we must pass the SQL command via the command
99+
# line not stdin, else Perl may spit up trying to write to stdin of
100+
# an already-failed psql process.
98101
my ($ret, $stdout, $stderr) =
99-
$node1->psql('postgres', 'SHOW port;',
100-
extra_params => [ '-d', $connstr ]);
102+
$node1->psql('postgres', undef,
103+
extra_params => [ '-d', $connstr, '-c', 'SHOW port;' ]);
101104
if ($status == 0)
102105
{
103-
is( $status == $ret && $stdout eq $target_node->port,
106+
is( $status == $ret && $stdout eq $target_port,
104107
1,
105-
"connect to node $target_name if mode \"$mode\" and $node1_name,$node2_name listed"
108+
"connect to node $target_name with mode \"$mode\" and $node1_name,$node2_name listed"
106109
);
107110
}
108111
else
@@ -112,9 +115,9 @@ sub test_target_session_attrs
112115
print "stdout = $stdout\n";
113116
print "stderr = $stderr\n";
114117

115-
is( $status == $ret,
118+
is( $status == $ret && !defined $target_node,
116119
1,
117-
"fail to connect to any nodes if mode \"$mode\" and $node1_name,$node2_name listed"
120+
"fail to connect with mode \"$mode\" and $node1_name,$node2_name listed"
118121
);
119122
}
120123

0 commit comments

Comments
 (0)