pgsql: Refactor background psql TAP functions

Started by Daniel Gustafssonover 3 years ago7 messagescomitters
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t232173
psql -h localhost -U postgres

Built from patchset v6 (message #6), August 18, 2026 at 03:25 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t232173_6 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t232173_6 && git checkout t232173_6

Patchset v6 (message #6) is on t232173_6

Jump to latest
#1Daniel Gustafsson
daniel@yesql.se

Refactor background psql TAP functions

This breaks out the background and interactive psql functionality into a
new class, PostgreSQL::Test::BackgroundPsql. Sessions are still initiated
via PostgreSQL::Test::Cluster, but once started they can be manipulated by
the new helper functions which intend to make querying easier. A sample
session for a command which can be expected to finish at a later time can
be seen below.

my $session = $node->background_psql('postgres');
$bsession->query_until(qr/start/, q(
\echo start
CREATE INDEX CONCURRENTLY idx ON t(a);
));
$bsession->quit;

Patch by Andres Freund with some additional hacking by me.

Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: /messages/by-id/20230130194350.zj5v467x4jgqt3d6@awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/664d757531e11ea5ef6971884ddb2a7af6fae69a

Modified Files
--------------
contrib/amcheck/t/003_cic_2pc.pl | 70 ++---
src/bin/psql/t/010_tab_completion.pl | 28 +-
src/test/perl/PostgreSQL/Test/BackgroundPsql.pm | 299 +++++++++++++++++++++
src/test/perl/PostgreSQL/Test/Cluster.pm | 79 ++----
.../recovery/t/010_logical_decoding_timelines.pl | 1 -
src/test/recovery/t/031_recovery_conflict.pl | 102 ++-----
src/test/subscription/t/015_stream.pl | 51 ++--
7 files changed, 388 insertions(+), 242 deletions(-)

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Daniel Gustafsson (#1)
Re: pgsql: Refactor background psql TAP functions

On 07.04.23 22:21, Daniel Gustafsson wrote:

Refactor background psql TAP functions

This breaks out the background and interactive psql functionality into a
new class, PostgreSQL::Test::BackgroundPsql.

The new file also needs to be installed in
src/test/perl/{Makefile,meson.build}.

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Peter Eisentraut (#2)
Re: pgsql: Refactor background psql TAP functions

On 26 Apr 2023, at 08:28, Peter Eisentraut <peter.eisentraut@enterprisedb.com> wrote:

On 07.04.23 22:21, Daniel Gustafsson wrote:

Refactor background psql TAP functions
This breaks out the background and interactive psql functionality into a
new class, PostgreSQL::Test::BackgroundPsql.

The new file also needs to be installed in src/test/perl/{Makefile,meson.build}.

Ugh, sorry about that. Fixing.

--
Daniel Gustafsson

#4Damir Belyalov
dam.bel07@gmail.com
In reply to: Daniel Gustafsson (#3)
Re: pgsql: Refactor background psql TAP functions

Hello!

There is another perl module: AdjustUpgrade.pm that is not in Makefile. Do
we need it?

$(INSTALL_DATA) $(srcdir)/PostgreSQL/Test/RecursiveCopy.pm
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/RecursiveCopy.pm'
$(INSTALL_DATA) $(srcdir)/PostgreSQL/Test/Cluster.pm
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/Cluster.pm'
$(INSTALL_DATA) $(srcdir)/PostgreSQL/Test/BackgroundPsql.pm
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/BackgroundPsql.pm'
+ $(INSTALL_DATA) $(srcdir)/PostgreSQL/Test/BackgroundPsql.pm
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/AdjustUpgrade.pm'
$(INSTALL_DATA) $(srcdir)/PostgreSQL/Version.pm
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Version.pm'

uninstall:
@@ -32,6 +33,7 @@ uninstall:
rm -f
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/RecursiveCopy.pm'
rm -f '$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/Cluster.pm'
rm -f
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/BackgroundPsql.pm'
+ rm -f
'$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/AdjustUpgrade.pm'
rm -f '$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Version.pm'

Regards,
Damir Belyalov
Postgres Professional

#5Daniel Gustafsson
daniel@yesql.se
In reply to: Damir Belyalov (#4)
Re: pgsql: Refactor background psql TAP functions

On 16 May 2023, at 21:04, Damir Belyalov <dam.bel07@gmail.com> wrote:

There is another perl module: AdjustUpgrade.pm that is not in Makefile. Do we need it?

Yes, I think it should be installed too and skimming the linked thread I see no
mention of the omission being deliberate. I will take care of it.

+ $(INSTALL_DATA) $(srcdir)/PostgreSQL/Test/BackgroundPsql.pm '$(DESTDIR)$(pgxsdir)/$(subdir)/PostgreSQL/Test/AdjustUpgrade.pm'

This is wrong though, but no need to send a new version of this small thing.

--
Daniel Gustafsson

#6Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#5)
Re: pgsql: Refactor background psql TAP functions

On 16 May 2023, at 21:43, Daniel Gustafsson <dgustafsson@postgresql.org> wrote:

On 16 May 2023, at 21:04, Damir Belyalov <dam.bel07@gmail.com> wrote:

There is another perl module: AdjustUpgrade.pm that is not in Makefile. Do we need it?

Yes, I think it should be installed too and skimming the linked thread I see no
mention of the omission being deliberate. I will take care of it.

The attached is the proposed fix, which will have to be backpatched to v11 to
match the original commit. Unless there are reasons to treat this module
differently from the others wrt installation I'll go ahead and fix it in time
for beta1.

--
Daniel Gustafsson

Attachments:

t232173_6
v1-0001-Add-installation-rules-for-AdjustUpgrade-test-mod.patchapplication/octet-stream; name=v1-0001-Add-installation-rules-for-AdjustUpgrade-test-mod.patch; x-unix-mode=0644Download+3-1
#7Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#6)
Re: pgsql: Refactor background psql TAP functions

On 17 May 2023, at 14:38, Daniel Gustafsson <dgustafsson@postgresql.org> wrote:

On 16 May 2023, at 21:43, Daniel Gustafsson <dgustafsson@postgresql.org> wrote:

On 16 May 2023, at 21:04, Damir Belyalov <dam.bel07@gmail.com> wrote:

There is another perl module: AdjustUpgrade.pm that is not in Makefile. Do we need it?

Yes, I think it should be installed too and skimming the linked thread I see no
mention of the omission being deliberate. I will take care of it.

The attached is the proposed fix, which will have to be backpatched to v11 to
match the original commit. Unless there are reasons to treat this module
differently from the others wrt installation I'll go ahead and fix it in time
for beta1.

After another round of thinking I opted out of pushing this, as the module is
so tied to pg_upgrade and the regress env it's use in installed pgxs is
questionable. While I would prefer a 1:1 between the modules in the source
tree and the installed tree, this module doesn't seem like a great fit for
installation.

--
Daniel Gustafsson