From 2b027a1ee8485b3d513f565c329bfd63a605df75 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 10 Nov 2014 10:25:28 +0000 Subject: [PATCH] Test relate-based function interruptibility (#2975) Also refactor existing interruptibility tests to avoid failures due to lack of latest GEOS version. Work funded by CartoDB git-svn-id: http://svn.osgeo.org/postgis/trunk@13122 b70326c6-7e19-0410-871a-916f4a2858ee --- regress/Makefile.in | 9 ++++- regress/interrupt.sql | 57 +++++++++++++++++----------- regress/interrupt_buffer.sql | 44 ++++++++++++++++++++++ regress/interrupt_buffer_expected | 3 ++ regress/interrupt_expected | 2 - regress/interrupt_relate.sql | 62 +++++++++++++++++++++++++++++++ regress/interrupt_relate_expected | 16 ++++++++ 7 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 regress/interrupt_buffer.sql create mode 100644 regress/interrupt_buffer_expected create mode 100644 regress/interrupt_relate.sql create mode 100644 regress/interrupt_relate_expected diff --git a/regress/Makefile.in b/regress/Makefile.in index 3bbada71c..34d0d8b6c 100644 --- a/regress/Makefile.in +++ b/regress/Makefile.in @@ -17,6 +17,7 @@ TMPDIR?=/tmp POSTGIS_PGSQL_VERSION=@POSTGIS_PGSQL_VERSION@ POSTGIS_GEOS_VERSION=@POSTGIS_GEOS_VERSION@ +GEOS_NUMERIC_VERSION=@GEOS_NUMERIC_VERSION@ POSTGIS_PROJ_VERSION=@POSTGIS_PROJ_VERSION@ POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@ POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@ @@ -159,7 +160,13 @@ ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 34),1) # GEOS-3.4 adds: # ST_DelaunayTriangles TESTS += \ - delaunaytriangles + delaunaytriangles \ + interrupt_buffer +endif + +ifeq ($(shell expr $(GEOS_NUMERIC_VERSION) ">=" 30403),1) + TESTS += \ + interrupt_relate endif ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 35),1) diff --git a/regress/interrupt.sql b/regress/interrupt.sql index 5563bfb46..9fa0b3e27 100644 --- a/regress/interrupt.sql +++ b/regress/interrupt.sql @@ -1,30 +1,43 @@ -CREATE TEMPORARY TABLE _time AS SELECT now() t; +-- liblwgeom interruption -SET statement_timeout TO 100; +CREATE TEMPORARY TABLE _time AS SELECT now() t; -select ST_Buffer(g,100) from ( - select (st_dumppoints(st_buffer(st_makepoint(0,0),10000,100000))).geom g -) foo; +CREATE FUNCTION _timecheck(label text, tolerated interval) RETURNS text +AS $$ +DECLARE + ret TEXT; + lap INTERVAL; +BEGIN + lap := now()-t FROM _time; + IF lap <= tolerated THEN ret := label || ' interrupted on time'; + ELSE ret := label || ' interrupted late: ' || lap; + END IF; + UPDATE _time SET t = now(); + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' VOLATILE; --- it may take some more to interrupt st_buffer, see --- https://travis-ci.org/postgis/postgis/builds/40211116#L2222-L2223 -SELECT CASE WHEN now()-t < '200ms'::interval THEN - 'buffer interrupted on time' - ELSE - 'buffer interrupted late: ' || ( now()-t )::text - END FROM _time; UPDATE _time SET t = now(); +CREATE TEMP TABLE _inputs AS +SELECT 1::int as id, ST_Collect(g) g FROM ( + SELECT ST_MakeLine( + ST_Point(cos(radians(x)),sin(radians(270-x))), + ST_Point(sin(radians(x)),cos(radians(60-x))) + ) g + FROM generate_series(1,720) x + ) foo +; -SELECT -ST_Segmentize(ST_MakeLine(ST_MakePoint(4,39), ST_MakePoint(1,41)), - 1e-100); -SELECT CASE WHEN now()-t < '150ms'::interval THEN - 'segmentize interrupted on time' - ELSE - 'segmentize interrupted late: ' || ( now()-t )::text - END FROM _time; UPDATE _time SET t = now(); +----------------- +-- ST_Segmentize +----------------- +SET statement_timeout TO 100; +SELECT ST_Segmentize(ST_MakeLine(ST_Point(4,39), ST_Point(1,41)), 1e-100); +SELECT _timecheck('segmentize', '150ms'); SET statement_timeout TO 0; - --- Not affected by timeout +-- Not affected by old timeout SELECT '1',ST_AsText(ST_Segmentize('LINESTRING(0 0,4 0)'::geometry, 2)); + + +DROP FUNCTION _timecheck(text, interval); diff --git a/regress/interrupt_buffer.sql b/regress/interrupt_buffer.sql new file mode 100644 index 000000000..8676bae49 --- /dev/null +++ b/regress/interrupt_buffer.sql @@ -0,0 +1,44 @@ +CREATE TEMPORARY TABLE _time AS SELECT now() t; + +CREATE FUNCTION _timecheck(label text, tolerated interval) RETURNS text +AS $$ +DECLARE + ret TEXT; + lap INTERVAL; +BEGIN + lap := now()-t FROM _time; + IF lap <= tolerated THEN ret := label || ' interrupted on time'; + ELSE ret := label || ' interrupted late: ' || lap; + END IF; + UPDATE _time SET t = now(); + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' VOLATILE; + +CREATE TEMP TABLE _inputs AS +SELECT 1::int as id, ST_Collect(g) g FROM ( + SELECT ST_MakeLine( + ST_Point(cos(radians(x)),sin(radians(270-x))), + ST_Point(sin(radians(x)),cos(radians(60-x))) + ) g + FROM generate_series(1,720) x + ) foo +; + + +----------------- +-- ST_Buffer +----------------- + +SET statement_timeout TO 100; +select ST_Buffer(g,100) from _inputs WHERE id = 1; +--( select (st_dumppoints(st_buffer(st_makepoint(0,0),10000,100000))).geom g) foo; +-- it may take some more to interrupt st_buffer, see +-- https://travis-ci.org/postgis/postgis/builds/40211116#L2222-L2223 +SELECT _timecheck('buffer', '200ms'); + +-- Not affected by old timeout +SELECT '1', ST_NPoints(ST_Buffer('POINT(4 0)'::geometry, 2, 1)); + + +DROP FUNCTION _timecheck(text, interval); diff --git a/regress/interrupt_buffer_expected b/regress/interrupt_buffer_expected new file mode 100644 index 000000000..f7004e0f7 --- /dev/null +++ b/regress/interrupt_buffer_expected @@ -0,0 +1,3 @@ +ERROR: canceling statement due to statement timeout +buffer interrupted on time +1|5 diff --git a/regress/interrupt_expected b/regress/interrupt_expected index adf8e75e1..d6bbb771b 100644 --- a/regress/interrupt_expected +++ b/regress/interrupt_expected @@ -1,5 +1,3 @@ -ERROR: canceling statement due to statement timeout -buffer interrupted on time NOTICE: liblwgeom code interrupted ERROR: canceling statement due to statement timeout segmentize interrupted on time diff --git a/regress/interrupt_relate.sql b/regress/interrupt_relate.sql new file mode 100644 index 000000000..aef907596 --- /dev/null +++ b/regress/interrupt_relate.sql @@ -0,0 +1,62 @@ +CREATE TEMPORARY TABLE _time AS SELECT now() t; + +CREATE FUNCTION _timecheck(label text, tolerated interval) RETURNS text +AS $$ +DECLARE + ret TEXT; + lap INTERVAL; +BEGIN + lap := now()-t FROM _time; + IF lap <= tolerated THEN ret := label || ' interrupted on time'; + ELSE ret := label || ' interrupted late: ' || lap; + END IF; + UPDATE _time SET t = now(); + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' VOLATILE; + +CREATE TEMP TABLE _inputs AS +SELECT 1::int as id, ST_Collect(g) g FROM ( + SELECT ST_MakeLine( + ST_Point(cos(radians(x)),sin(radians(270-x))), + ST_Point(sin(radians(x)),cos(radians(60-x))) + ) g + FROM generate_series(1,720) x + ) foo +; + + +----------------------------- +-- IM9 based predicates +-- +-- These require GEOS-3.4.3+ +----------------------------- + +SET statement_timeout TO 100; + +select ST_Contains(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('contains', '200ms'); + +select ST_Covers(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('covers', '200ms'); + +select ST_CoveredBy(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('coveredby', '200ms'); + +select ST_Crosses(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('crosses', '200ms'); + +select ST_Equals(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('crosses', '200ms'); + +select ST_Intersects(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('crosses', '200ms'); + +select ST_Overlaps(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('crosses', '200ms'); + +select ST_Relate(g,g) from _inputs WHERE id = 1; -- 6+ seconds +SELECT _timecheck('relate', '200ms'); + + +DROP FUNCTION _timecheck(text, interval); diff --git a/regress/interrupt_relate_expected b/regress/interrupt_relate_expected new file mode 100644 index 000000000..d2f78025c --- /dev/null +++ b/regress/interrupt_relate_expected @@ -0,0 +1,16 @@ +ERROR: canceling statement due to statement timeout +contains interrupted on time +ERROR: canceling statement due to statement timeout +covers interrupted on time +ERROR: canceling statement due to statement timeout +coveredby interrupted on time +ERROR: canceling statement due to statement timeout +crosses interrupted on time +ERROR: canceling statement due to statement timeout +crosses interrupted on time +ERROR: canceling statement due to statement timeout +crosses interrupted on time +ERROR: canceling statement due to statement timeout +crosses interrupted on time +ERROR: canceling statement due to statement timeout +relate interrupted on time -- 2.40.0