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

Commit f1ce8d6

Browse files
danielgustafssonCommitfest Bot
authored and
Commitfest Bot
committed
Report test failure rather than aborting in case of timeout
When an querying an interactive, or background, psql process the call would die() in case of a timeout since it used the IPC::Run timeout construct and not a timer. This aborts tests prematurely which makes debugging harder, and stops getting results for the remaining tests in the suite. This converts to using a timer object instead which will transfer control back to the caller regardless, returning undef in case of a timeout along with logging a test failure. Affected callsites are also updated to reflect this. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/1100715.1712265845@sss.pgh.pa.us
1 parent a5b6edf commit f1ce8d6

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/test/modules/test_misc/t/005_timeouts.pl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,7 @@
118118

119119
# We just initialize the GUC and wait. No transaction is required.
120120
$psql_session = $node->background_psql('postgres');
121-
$psql_session->query_until(
122-
qr/starting_bg_psql/, q(
123-
\echo starting_bg_psql
124-
SET idle_session_timeout to '10ms';
125-
));
121+
$psql_session->query(q(SET idle_session_timeout to '10ms';));
126122

127123
# Wait until the backend enters the timeout injection point.
128124
$node->wait_for_event('client backend', 'idle-session-timeout');

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ sub new
100100
"Forbidden caller of constructor: package: $package, file: $file:$line"
101101
unless $package->isa('PostgreSQL::Test::Cluster');
102102

103-
$psql->{timeout} = IPC::Run::timeout(
103+
$psql->{timeout} = IPC::Run::timer(
104104
defined($timeout)
105105
? $timeout
106106
: $PostgreSQL::Test::Utils::timeout_default);
@@ -179,8 +179,10 @@ sub wait_connect
179179
180180
=item $session->quit
181181
182-
Close the session and clean up resources. Each test run must be closed with
183-
C<quit>.
182+
Close the psql session and clean up resources. Each psql session must be
183+
closed with C<quit> before the end of the test. Returns TRUE if psql exited
184+
successfully (i.e. with zero exit code), otherwise returns FALSE and reports
185+
a test failure.
184186
185187
=cut
186188

@@ -190,7 +192,9 @@ sub quit
190192

191193
$self->{stdin} .= "\\q\n";
192194

193-
return $self->{run}->finish;
195+
my $ret = $self->{run}->finish;
196+
ok($ret, 'Terminating interactive psql session');
197+
return $ret;
194198
}
195199

196200
=pod
@@ -274,7 +278,8 @@ sub query
274278
$self->{run}, $self->{timeout},
275279
\$self->{stderr}, qr/$banner_match/);
276280

277-
die "psql query timed out" if $self->{timeout}->is_expired;
281+
ok(!$self->{timeout}->is_expired, 'psql query timed out') || return;
282+
$output = $self->{stdout};
278283

279284
note "results query $query_cnt:\n",
280285
explain {
@@ -342,7 +347,8 @@ sub query_until
342347

343348
pump_until($self->{run}, $self->{timeout}, \$self->{stdout}, $until);
344349

345-
die "psql query timed out" if $self->{timeout}->is_expired;
350+
ok(!$self->{timeout}->is_expired, 'psql query_until did not time out')
351+
|| return;
346352

347353
$ret = $self->{stdout};
348354

src/test/recovery/t/031_recovery_conflict.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
-- wait for lock held by prepared transaction
254254
SELECT * FROM $table2;
255255
]);
256-
ok(1,
256+
isnt($res, undef,
257257
"$sect: cursor holding conflicting pin, also waiting for lock, established"
258258
);
259259

0 commit comments

Comments
 (0)