Move hard-coded upgrade data from run_test.pl to hook scripts

main
Sandro Santilli 2021-05-04 18:13:22 +02:00
parent 30706a68a7
commit 155a4e664b
14 changed files with 79 additions and 125 deletions

View File

@ -41,7 +41,7 @@ clean-local:
# TODO: drop 'test' target..
test: check
check: check-no-trailing-blanks check-unit check-regress docs-check check-news
check: check-no-trailing-blanks check-unit check-regress docs-check check-news
staged-install: all
$(MAKE) -C regress staged-install
@ -197,11 +197,9 @@ ifeq ($(HAVE_SFCGAL),yes)
include sfcgal/regress/tests.mk
endif
ifeq (@TOPOLOGY@,topology)
override RUNTESTFLAGS := $(RUNTESTFLAGS) --topology
include topology/test/tests.mk
endif
ifeq (@RASTER@,raster)
override RUNTESTFLAGS := $(RUNTESTFLAGS) --raster
include raster/test/regress/tests.mk
endif

View File

@ -180,9 +180,8 @@ rtpostgis.sql: ../../rt_pg/rtpostgis.sql
$(PERL) -lpe "s'\\\$$libdir'$(REGRESS_INSTALLDIR)/lib'g" $< > $@
override RUNTESTFLAGS := $(RUNTESTFLAGS) --raster
topsrcdir = $(realpath ../../../)
srcdir = $(realpath .)
include tests.mk
include ../../../regress/runtest.mk

View File

@ -0,0 +1 @@
DROP TABLE upgrade_test_raster;

View File

@ -0,0 +1,16 @@
CREATE TABLE upgrade_test_raster(r raster);
INSERT INTO upgrade_test_raster(r) VALUES
(
ST_AddBand(
ST_MakeEmptyRaster(
10, 10, 1, 1, 2, 2, 0, 0,4326
),
1,
'8BSI'::text,
-129,
NULL
)
);
--SET client_min_messages TO ERROR;
SELECT AddRasterConstraints('upgrade_test_raster', 'r');

View File

@ -10,6 +10,12 @@
# *
# **********************************************************************
override RUNTESTFLAGS := $(RUNTESTFLAGS) --raster
RUNTESTFLAGS_INTERNAL += \
--before-upgrade-script $(topsrcdir)/raster/test/regress/hooks/hook-before-upgrade-raster.sql \
--after-upgrade-script $(topsrcdir)/raster/test/regress/hooks/hook-after-upgrade-raster.sql
RASTER_TEST_FIRST = \
$(topsrcdir)/raster/test/regress/check_gdal \
$(topsrcdir)/raster/test/regress/load_outdb

View File

@ -20,6 +20,10 @@ INTERRUPTTESTS=@INTERRUPTTESTS@
current_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
RUNTESTFLAGS_INTERNAL += \
--before-upgrade-script $(topsrcdir)/regress/hooks/hook-before-upgrade.sql \
--after-upgrade-script $(topsrcdir)/regress/hooks/hook-after-upgrade.sql
TESTS += \
$(topsrcdir)/regress/core/affine \
$(topsrcdir)/regress/core/bestsrid \
@ -153,7 +157,7 @@ endif
ifeq ($(shell expr "$(POSTGIS_GEOS_VERSION)" ">=" 31000),1)
TESTS += \
$(topsrcdir)/regress/core/geos310
$(topsrcdir)/regress/core/geos310
endif
ifeq ($(INTERRUPTTESTS),yes)

View File

@ -0,0 +1,2 @@
DROP VIEW IF EXISTS upgrade_view_test;
DROP TABLE upgrade_test;

View File

@ -0,0 +1,26 @@
CREATE TABLE upgrade_test(g1 geometry, g2 geography);
INSERT INTO upgrade_test(g1,g2) VALUES
('POINT(0 0)', 'LINESTRING(0 0, 1 1)'),
('POINT(1 0)', 'LINESTRING(0 1, 1 1)');
-- We know upgrading with an st_union() based view
-- fails unless you're on PostgreSQL 12, so we don't
-- even try that.
--
-- We could re-enable this test IF we fix the upgrade
-- in pre-12 versions. Refer to
-- https://trac.osgeo.org/postgis/ticket/4386
--
DO $BODY$
DECLARE
vernum INT;
BEGIN
show server_version_num INTO vernum;
IF vernum >= 120000
THEN
RAISE DEBUG '12+ server (%)', vernum;
CREATE VIEW upgrade_view_test AS
SELECT ST_Union(g1) FROM upgrade_test;
END IF;
END;
$BODY$ LANGUAGE 'plpgsql';

View File

@ -94,7 +94,7 @@ GetOptions (
'after-create-script=s' => \@OPT_HOOK_AFTER_CREATE,
'before-uninstall-script=s' => \@OPT_HOOK_BEFORE_UNINSTALL,
'before-upgrade-script=s' => \@OPT_HOOK_BEFORE_UPGRADE,
'after-upgrade-script=s' => \@OPT_HOOK_BEFORE_UPGRADE
'after-upgrade-script=s' => \@OPT_HOOK_AFTER_UPGRADE
);
if ( @ARGV < 1 )
@ -297,114 +297,6 @@ sub semver_lessthan
return @bcomp ? 1 : 0;
}
sub create_upgrade_test_objects
{
# TODO: replace the following with --before-upgrade-script usage
my $query = "create table upgrade_test(g1 geometry, g2 geography";
$query .= ", r raster" if ( $OPT_WITH_RASTER );
$query .= ")";
my $ret = sql($query);
unless ( $ret =~ /^CREATE/ ) {
`dropdb $DB`;
print "\nSomething went wrong creating upgrade_test table: $ret.\n";
exit(1);
}
$query = "insert into upgrade_test(g1,g2) values ";
$query .= "('POINT(0 0)', 'LINESTRING(0 0, 1 1)'), ";
$query .= "('POINT(1 0)', 'LINESTRING(0 1, 1 1)');";
my $ret = sql($query);
unless ( $ret =~ /^INSERT/ ) {
`dropdb $DB`;
print "\nSomething went wrong populating upgrade_test table: $ret.\n";
exit(1);
}
if ( $pgvernum >= 120000 ) {
# We know upgrading with an st_union() based view
# fails unless you're on PostgreSQL 12, so we don't
# even try that.
#
# We could re-enable this test IF we fix the upgrade
# in pre-12 versions. Refer to
# https://trac.osgeo.org/postgis/ticket/4386
#
$query = "create view upgrade_view_test as ";
$query .= "select st_union(g1) from upgrade_test;";
my $ret = sql($query);
unless ( $ret =~ /^CREATE/ ) {
`dropdb $DB`;
print "\nSomething went wrong creating upgrade_view_test view: $ret.\n";
exit(1);
}
}
if ( $OPT_WITH_RASTER )
{
$query = "UPDATE upgrade_test SET r = ";
$query .= " ST_AddBand(ST_MakeEmptyRaster(10, 10, 1, 1, 2, 2, 0, 0,4326), 1, '8BSI'::text, -129, NULL);";
$ret = sql($query);
unless ( $ret =~ /^UPDATE/ ) {
`dropdb $DB`;
print "\nSomething went wrong setting raster into upgrade_test table: $ret.\n";
exit(1);
}
$query = "set client_min_messages to error; select AddRasterConstraints('upgrade_test', 'r')";
$ret = sql($query);
unless ( $ret =~ /^t$/ ) {
`dropdb $DB`;
print "\nSomething went wrong adding raster constraints to upgrade_test: " . $ret . "\n";
exit(1);
}
}
if ( $OPT_WITH_TOPO )
{
$query = "select topology.createTopology('upgrade_test');";
$ret = sql($query);
unless ( $ret =~ /^[1-9][0-9]*$/ ) {
`dropdb $DB`;
print "\nSomething went wrong adding upgrade_test topology: " . $ret . "\n";
exit(1);
}
}
}
sub drop_upgrade_test_objects
{
# TODO: allow passing the "upgrade-cleanup" script via commandline
my $ret = sql("drop view if exists upgrade_view_test;");
unless ( $ret =~ /^DROP/ ) {
`dropdb $DB`;
print "\nSomething went wrong dropping spatial view: $ret.\n";
exit(1);
}
my $ret = sql("drop table upgrade_test;");
unless ( $ret =~ /^DROP/ ) {
`dropdb $DB`;
print "\nSomething went wrong dropping spatial tables: $ret.\n";
exit(1);
}
if ( $OPT_WITH_TOPO )
{
my $query = "SELECT topology.DropTopology('upgrade_test');";
$ret = sql($query);
unless ( $ret =~ /^Topology 'upgrade_test' dropped$/ ) {
`dropdb $DB`;
print "\nSomething went wrong dropping upgrade_test topology: " . $ret . "\n";
exit(1);
}
}
}
if ( $OPT_UPGRADE )
{
print "Upgrading from postgis $libver\n";
@ -415,8 +307,6 @@ if ( $OPT_UPGRADE )
die unless load_sql_file($hook, 1);
}
create_upgrade_test_objects();
if ( $OPT_EXTENSIONS )
{
upgrade_spatial_extensions();
@ -426,11 +316,9 @@ if ( $OPT_UPGRADE )
upgrade_spatial();
}
drop_upgrade_test_objects();
foreach my $hook (@OPT_HOOK_AFTER_UPGRADE)
{
print " Running after-upgrade-script $hook\n";
print "Running after-upgrade-script $hook\n";
die unless load_sql_file($hook, 1);
}

View File

@ -4,17 +4,22 @@ abssrcdir := $(realpath .)
TESTS := $(patsubst $(topsrcdir)/%,$(abstopsrcdir)/%,$(TESTS))
TESTS := $(patsubst $(abssrcdir)/%,./%,$(TESTS))
check-regress:
@$(PERL) $(topsrcdir)/regress/run_test.pl $(RUNTESTFLAGS) $(TESTS)
@echo "RUNTESTFLAGS: $(RUNTESTFLAGS)"
@echo "RUNTESTFLAGS_INTERNAL: $(RUNTESTFLAGS_INTERNAL)"
@$(PERL) $(topsrcdir)/regress/run_test.pl $(RUNTESTFLAGS) $(RUNTESTFLAGS_INTERNAL) $(TESTS)
#
# Will now run upgrade test if RUNTESTFLAGS was not already doing that
#
@if echo "$(RUNTESTFLAGS)" | grep -vq -- --upgrade; then \
$(PERL) $(topsrcdir)/regress/run_test.pl --upgrade $(RUNTESTFLAGS) $(TESTS); \
$(PERL) $(topsrcdir)/regress/run_test.pl \
--upgrade \
$(RUNTESTFLAGS) \
$(TESTS); \
fi
check-long:

View File

@ -39,9 +39,8 @@ check-regress: check-regress-deps
check-regress-deps: topo_predicates.sql load_topology.sql load_topology-4326.sql
override RUNTESTFLAGS := $(RUNTESTFLAGS) --topology
topsrcdir = $(realpath ../../)
srcdir = $(realpath .)
include tests.mk
include ../../regress/runtest.mk

View File

@ -0,0 +1,2 @@
SELECT topology.DropTopology('upgrade_test');

View File

@ -0,0 +1,2 @@
SELECT topology.createTopology('upgrade_test');

View File

@ -10,6 +10,12 @@
# *
# **********************************************************************
override RUNTESTFLAGS := $(RUNTESTFLAGS) --topology
RUNTESTFLAGS_INTERNAL += \
--before-upgrade-script $(topsrcdir)/topology/test/regress/hooks/hook-before-upgrade-topology.sql \
--after-upgrade-script $(topsrcdir)/topology/test/regress/hooks/hook-after-upgrade-topology.sql
TESTS += \
$(topsrcdir)/topology/test/regress/addedge.sql \
$(topsrcdir)/topology/test/regress/addface2.5d.sql \