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@
# 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)
-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);
--- /dev/null
+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);
--- /dev/null
+ERROR: canceling statement due to statement timeout
+buffer interrupted on time
+1|5
-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
--- /dev/null
+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);
--- /dev/null
+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