Adjust timestamp regression tests to prevent two low-probability failure

cases.  Recent buildfarm experience shows that it is sometimes possible
to execute several SQL commands in less time than the granularity of
Windows' not-very-high-resolution gettimeofday(), leading to a failure
because the tests expect the value of now() to change and it doesn't.
Also, it was recognized some time ago that the same area of the tests
could fail if local midnight passes between the insertion and the checking
of the values for 'yesterday', 'tomorrow', etc.  Clean all this up per
ideas from myself and Greg Stark.

There remains a window for failure if the transaction block is entered
exactly at local midnight (so that 'now' and 'today' have the same value),
but that seems low-probability enough to live with.

Since the point of this change is mostly to eliminate buildfarm noise,
back-patch to all versions we are still actively testing.
This commit is contained in:
Tom Lane 2008-05-25 21:51:00 +00:00
parent d82e7c84fa
commit 8c2ac75c5c
4 changed files with 126 additions and 39 deletions

View File

@ -1,18 +1,28 @@
-- --
-- TIMESTAMP -- TIMESTAMP
-- --
CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone); CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone);
-- Shorthand values -- Test shorthand input values
-- Not directly usable for regression testing since these are not constants. -- We can't just "select" the results since they aren't constants; test for
-- So, just try to test parser and hope for the best - thomas 97/04/26 -- equality instead. We can do that by running the test inside a transaction
-- NB: could get a failure if local midnight passes during the next few -- block, within which the value of 'now' shouldn't change. We also check
-- statements. -- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
INSERT INTO TIMESTAMP_TBL VALUES ('current');
ERROR: date/time value "current" is no longer supported
INSERT INTO TIMESTAMP_TBL VALUES ('today'); INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
-- time zone should be ignored by this data type
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
@ -21,10 +31,10 @@ SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone
1 1
(1 row) (1 row)
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow'; SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
one three
----- -------
3 3
(1 row) (1 row)
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
@ -33,24 +43,37 @@ SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone
1 1
(1 row) (1 row)
SELECT count(*) AS None FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'now'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
none one
------ -----
0 1
(1 row) (1 row)
COMMIT;
DELETE FROM TIMESTAMP_TBL; DELETE FROM TIMESTAMP_TBL;
-- verify uniform transaction time within transaction block -- verify uniform transaction time within transaction block
BEGIN; BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now'; SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
two two
----- -----
2 2
(1 row) (1 row)
END; COMMIT;
DELETE FROM TIMESTAMP_TBL; DELETE FROM TIMESTAMP_TBL;
-- Special values -- Special values
INSERT INTO TIMESTAMP_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMP_TBL VALUES ('-infinity');
@ -59,6 +82,8 @@ INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid'); INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
ERROR: date/time value "invalid" is no longer supported ERROR: date/time value "invalid" is no longer supported
INSERT INTO TIMESTAMP_TBL VALUES ('current');
ERROR: date/time value "current" is no longer supported
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime'); INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');

View File

@ -1,10 +1,24 @@
-- --
-- TIMESTAMPTZ -- TIMESTAMPTZ
-- --
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone); CREATE TABLE TIMESTAMPTZ_TBL (d1 timestamp(2) with time zone);
-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
-- equality instead. We can do that by running the test inside a transaction
-- block, within which the value of 'now' shouldn't change. We also check
-- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
BEGIN;
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
ERROR: date/time value "current" is no longer supported
INSERT INTO TIMESTAMPTZ_TBL VALUES ('today'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('today');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow');
@ -28,24 +42,37 @@ SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone
1 1
(1 row) (1 row)
SELECT count(*) AS None FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'now'; SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now';
none one
------ -----
0 1
(1 row) (1 row)
COMMIT;
DELETE FROM TIMESTAMPTZ_TBL; DELETE FROM TIMESTAMPTZ_TBL;
-- verify uniform transaction time within transaction block -- verify uniform transaction time within transaction block
BEGIN; BEGIN;
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
pg_sleep
----------
(1 row)
SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now'; SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now';
two two
----- -----
2 2
(1 row) (1 row)
END; COMMIT;
DELETE FROM TIMESTAMPTZ_TBL; DELETE FROM TIMESTAMPTZ_TBL;
-- Special values -- Special values
INSERT INTO TIMESTAMPTZ_TBL VALUES ('-infinity'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('-infinity');
@ -54,6 +81,8 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
ERROR: date/time value "invalid" is no longer supported ERROR: date/time value "invalid" is no longer supported
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
ERROR: date/time value "current" is no longer supported
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime');

View File

@ -2,35 +2,48 @@
-- TIMESTAMP -- TIMESTAMP
-- --
CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone); CREATE TABLE TIMESTAMP_TBL (d1 timestamp(2) without time zone);
-- Shorthand values -- Test shorthand input values
-- Not directly usable for regression testing since these are not constants. -- We can't just "select" the results since they aren't constants; test for
-- So, just try to test parser and hope for the best - thomas 97/04/26 -- equality instead. We can do that by running the test inside a transaction
-- NB: could get a failure if local midnight passes during the next few -- block, within which the value of 'now' shouldn't change. We also check
-- statements. -- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.
INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
INSERT INTO TIMESTAMP_TBL VALUES ('current');
INSERT INTO TIMESTAMP_TBL VALUES ('today'); INSERT INTO TIMESTAMP_TBL VALUES ('today');
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
-- time zone should be ignored by this data type
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow EST');
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu'); INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'today';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow'; SELECT count(*) AS Three FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'tomorrow';
SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'yesterday';
SELECT count(*) AS None FROM TIMESTAMP_TBL WHERE d1 = timestamp without time zone 'now'; SELECT count(*) AS One FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
COMMIT;
DELETE FROM TIMESTAMP_TBL; DELETE FROM TIMESTAMP_TBL;
-- verify uniform transaction time within transaction block -- verify uniform transaction time within transaction block
BEGIN; BEGIN;
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
INSERT INTO TIMESTAMP_TBL VALUES ('now'); INSERT INTO TIMESTAMP_TBL VALUES ('now');
SELECT pg_sleep(0.1);
SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now'; SELECT count(*) AS two FROM TIMESTAMP_TBL WHERE d1 = timestamp(2) without time zone 'now';
END; COMMIT;
DELETE FROM TIMESTAMP_TBL; DELETE FROM TIMESTAMP_TBL;
-- Special values -- Special values
@ -39,6 +52,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('infinity');
INSERT INTO TIMESTAMP_TBL VALUES ('epoch'); INSERT INTO TIMESTAMP_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMP_TBL VALUES ('invalid'); INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
INSERT INTO TIMESTAMP_TBL VALUES ('current');
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');

View File

@ -2,10 +2,23 @@
-- TIMESTAMPTZ -- TIMESTAMPTZ
-- --
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone); CREATE TABLE TIMESTAMPTZ_TBL (d1 timestamp(2) with time zone);
-- Test shorthand input values
-- We can't just "select" the results since they aren't constants; test for
-- equality instead. We can do that by running the test inside a transaction
-- block, within which the value of 'now' shouldn't change. We also check
-- that 'now' *does* change over a reasonable interval such as 100 msec.
-- NOTE: it is possible for this part of the test to fail if the transaction
-- block is entered exactly at local midnight; then 'now' and 'today' have
-- the same values and the counts will come out different.
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
BEGIN;
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('today'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('today');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow');
@ -15,16 +28,21 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow zulu');
SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'today'; SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'today';
SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'tomorrow'; SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'tomorrow';
SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'yesterday'; SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'yesterday';
SELECT count(*) AS None FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp with time zone 'now'; SELECT count(*) AS One FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now';
COMMIT;
DELETE FROM TIMESTAMPTZ_TBL; DELETE FROM TIMESTAMPTZ_TBL;
-- verify uniform transaction time within transaction block -- verify uniform transaction time within transaction block
BEGIN; BEGIN;
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
SELECT pg_sleep(0.1);
SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now'; SELECT count(*) AS two FROM TIMESTAMPTZ_TBL WHERE d1 = timestamp(2) with time zone 'now';
END; COMMIT;
DELETE FROM TIMESTAMPTZ_TBL; DELETE FROM TIMESTAMPTZ_TBL;
-- Special values -- Special values
@ -33,6 +51,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('infinity');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('epoch');
-- Obsolete special values -- Obsolete special values
INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
-- Postgres v6.0 standard output format -- Postgres v6.0 standard output format
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST'); INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');