Restart BackgroundPsql's timer more nicely.

Use BackgroundPsql's published API for automatically restarting
its timer for each query, rather than manually reaching into it
to achieve the same thing.

010_tab_completion.pl's logic for this predates the invention
of BackgroundPsql (and 664d75753 missed the opportunity to
make it cleaner).  030_pager.pl copied-and-pasted the code.

Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1100715.1712265845@sss.pgh.pa.us
This commit is contained in:
Daniel Gustafsson 2026-02-13 11:36:31 +01:00
parent 775fc01415
commit 53c6bd0aa3
2 changed files with 6 additions and 8 deletions

View file

@ -77,8 +77,10 @@ close $FH;
# for possible debugging purposes.
my $historyfile = "${PostgreSQL::Test::Utils::log_path}/010_psql_history.txt";
# fire up an interactive psql session
# fire up an interactive psql session and configure it such that each query
# restarts the timer
my $h = $node->interactive_psql('postgres', history_file => $historyfile);
$h->set_query_timer_restart();
# Simple test case: type something and see if psql responds as expected
sub check_completion
@ -88,9 +90,6 @@ sub check_completion
# report test failures from caller location
local $Test::Builder::Level = $Test::Builder::Level + 1;
# restart per-command timer
$h->{timeout}->start($PostgreSQL::Test::Utils::timeout_default);
# send the data to be sent and wait for its result
my $out = $h->query_until($pattern, $send);
my $okay = ($out =~ $pattern && !$h->{timeout}->is_expired);

View file

@ -70,8 +70,10 @@ $node->safe_psql(
25 as y,
26 as z');
# fire up an interactive psql session
# fire up an interactive psql session and configure it such that each query
# restarts the timer
my $h = $node->interactive_psql('postgres');
$h->set_query_timer_restart();
# set the pty's window size to known values
# (requires undesirable chumminess with the innards of IPC::Run)
@ -88,9 +90,6 @@ sub do_command
# report test failures from caller location
local $Test::Builder::Level = $Test::Builder::Level + 1;
# restart per-command timer
$h->{timeout}->start($PostgreSQL::Test::Utils::timeout_default);
# send the data to be sent and wait for its result
my $out = $h->query_until($pattern, $send);
my $okay = ($out =~ $pattern && !$h->{timeout}->is_expired);