sql-info.de
February 13, 2022

PostgreSQL | Adjusting multi-version compatible TAP tests for PostgreSQL 15

Commit b3b4d8e6 moves and renames the PostgresNode and TestLib Perl modules, which form the basis of the TAP tests, to a custom namespace (PostgreSQL::Test). While this makes sense for the reasons mentioned in the commit, it does mean that extensions providing TAP tests intended to run on PostgreSQL 14 and earlier will fail "out-of-the-box" on PostgreSQL 15 with errors like:

# Looks like your test exited with 25 before it could output anything.
Dubious, test returned 25 (wstat 6400, 0x1900)

and the regress_log file may contain something like:

Undefined subroutine ... get_new_node called at ... line ....

Fortunately it's simple enough to rectify this. The PostgreSQL version number is available during the build process as VERSION_NUM, so it's basically a case of exporting this as an environment variable to make it available to the test script(s) and adjusting those appropriately.

If your TAP tests are intended to running PostgreSQL 12 and later only, your extension Makefile should set TAP_TESTS (added to the extension buidling infrastructure in commit d3c09b9b), and export VERSION_NUM thusly (assuming GNU make 3.81 or later):

export PG_VERSION_NUM=$(VERSION_NUM)

If supporting PostgreSQL 11 and earlier, you'll need to explicitly add the environment variable to the TAP test build target, something along these lines:

installcheck: all
	rm -rf $(srcdir)/tmp_check/log
	cd $(srcdir) && PG_VERSION_NUM='$(VERSION_NUM)' TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" \
	PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' \
	$(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)

The test script(s) can then be modified thusly to include the correct Perl module for the running PostgreSQL version:

use if $ENV{PG_VERSION_NUM} >= 150000, 'PostgreSQL::Test::Cluster';
use if $ENV{PG_VERSION_NUM}  < 150000, 'PostgresNode';

Invocations of get_new_node() will then also need to be modified, e.g.:

my $node_name = 'test_node';
my $postgres_node = $ENV{PG_VERSION_NUM} >= 150000
   ? PostgreSQL::Test::Cluster->new( $node_name );
   : get_new_node( $node_name );

As far as I am aware (and I haven't checked in detail), no other changes should be necessary. At least, this was the case for the extension I am interested in. (Disclaimer: it's entirely possible there are other, possibly better ways of doing this).

Posted at 12:34 AM

Post a comment
Name:
*
E-Mail:
address will not be displayed
Homepage:
Comment: