]> granicus.if.org Git - postgis/commitdiff
Test relate-based function interruptibility (#2975)
authorSandro Santilli <strk@keybit.net>
Mon, 10 Nov 2014 10:25:28 +0000 (10:25 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 10 Nov 2014 10:25:28 +0000 (10:25 +0000)
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
regress/interrupt.sql
regress/interrupt_buffer.sql [new file with mode: 0644]
regress/interrupt_buffer_expected [new file with mode: 0644]
regress/interrupt_expected
regress/interrupt_relate.sql [new file with mode: 0644]
regress/interrupt_relate_expected [new file with mode: 0644]

index 3bbada71c9a721260b901ae4825c93005522a4b5..34d0d8b6ce96cb611e6ca44021c2575858dd0a62 100644 (file)
@@ -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)
index 5563bfb46805bf9b6cdcb6d5cf4cf6ca4e70843e..9fa0b3e2751faf6dcf0c7003758cc54fb1da6d46 100644 (file)
@@ -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 (file)
index 0000000..8676bae
--- /dev/null
@@ -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 (file)
index 0000000..f7004e0
--- /dev/null
@@ -0,0 +1,3 @@
+ERROR:  canceling statement due to statement timeout
+buffer interrupted on time
+1|5
index adf8e75e1ff1598fc7c56d5bce8f442bcae954e4..d6bbb771beefb8ec94266a06c4a9678b4f8fefdf 100644 (file)
@@ -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 (file)
index 0000000..aef9075
--- /dev/null
@@ -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 (file)
index 0000000..d2f7802
--- /dev/null
@@ -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