From 5bfe6a3c485d3259f59fa2d2e1d34dea1a3baeba Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Mon, 13 Jul 2020 10:54:26 +0900
Subject: Fix timestamp range handling in regression tests of
 modules/commit_ts/

Switching the regression tests to use tstzrange() has proved to not be a
good idea for environments where the timestamp precision is low, as
internal range checks exclude the upper bound.  So, if the commit
timestamp of a transaction matched with now() from the next query,
the test would fail.  This changes to use two bound checks instead of
the range function, where the upper bound is inclusive.

Per buildfarm member jacana.

Discussion: https://postgr.es/m/20200712122507.GD21680@paquier.xyz
---
 src/test/modules/commit_ts/sql/commit_timestamp.sql | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

(limited to 'src/test/modules/commit_ts/sql/commit_timestamp.sql')

diff --git a/src/test/modules/commit_ts/sql/commit_timestamp.sql b/src/test/modules/commit_ts/sql/commit_timestamp.sql
index e77dfb2f0a0..3bb7bb27a74 100644
--- a/src/test/modules/commit_ts/sql/commit_timestamp.sql
+++ b/src/test/modules/commit_ts/sql/commit_timestamp.sql
@@ -22,8 +22,9 @@ SELECT pg_xact_commit_timestamp('1'::xid);
 SELECT pg_xact_commit_timestamp('2'::xid);
 
 SELECT x.xid::text::bigint > 0 as xid_valid,
-    x.timestamp <@ tstzrange('-infinity'::timestamptz, now()) AS ts_in_range,
-    roident != 0 AS valid_roident
+       x.timestamp > '-infinity'::timestamptz AS ts_low,
+       x.timestamp <= now() AS ts_high,
+       roident != 0 AS valid_roident
   FROM pg_last_committed_xact() x;
 
 -- Test non-normal transaction ids.
@@ -34,10 +35,12 @@ SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL
 
 -- Test transaction without replication origin
 SELECT txid_current() as txid_no_origin \gset
-SELECT x.timestamp <@ tstzrange('-infinity'::timestamptz, now()) AS ts_in_range,
+SELECT x.timestamp > '-infinity'::timestamptz AS ts_low,
+       x.timestamp <= now() AS ts_high,
        roident != 0 AS valid_roident
   FROM pg_last_committed_xact() x;
-SELECT x.timestamp <@ tstzrange('-infinity'::timestamptz, now()) AS ts_in_range,
+SELECT x.timestamp > '-infinity'::timestamptz AS ts_low,
+       x.timestamp <= now() AS ts_high,
        roident != 0 AS valid_roident
   FROM pg_xact_commit_timestamp_origin(:'txid_no_origin') x;
 
@@ -46,10 +49,14 @@ SELECT pg_replication_origin_create('regress_commit_ts: get_origin') != 0
   AS valid_roident;
 SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin');
 SELECT txid_current() as txid_with_origin \gset
-SELECT x.timestamp <@ tstzrange('-infinity'::timestamptz, now()) AS ts_in_range, r.roname
+SELECT x.timestamp > '-infinity'::timestamptz AS ts_low,
+       x.timestamp <= now() AS ts_high,
+       r.roname
   FROM pg_last_committed_xact() x, pg_replication_origin r
   WHERE r.roident = x.roident;
-SELECT x.timestamp <@ tstzrange('-infinity'::timestamptz, now()) AS ts_in_range, r.roname
+SELECT x.timestamp > '-infinity'::timestamptz AS ts_low,
+       x.timestamp <= now() AS ts_high,
+       r.roname
   FROM pg_xact_commit_timestamp_origin(:'txid_with_origin') x, pg_replication_origin r
   WHERE r.roident = x.roident;
 
-- 
cgit v1.2.3

