Skip to content

Commit

Permalink
Merge pull request #39 from jfinzel/test_fixes
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
vipgh0828 authored Jan 23, 2019
2 parents ba8e775 + e6c3a8b commit f83ea71
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
pgl-ddl-deploy (1.5.1-1) unstable; urgency=medium

* Fix test race conditions and unstable output

-- Jeremy Finzel <jfinzel@enova.com> Tue, 15 Jan 2019 11:04:16 -0600

pgl-ddl-deploy (1.5.0-1) unstable; urgency=medium

* Support more commands and allow kill blocking subscriber processes
Expand Down
73 changes: 37 additions & 36 deletions expected/25_1_5_features.out
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ SELECT * FROM pgl_ddl_deploy.exceptions;

CREATE TABLE public.foo(id serial primary key, bla int);
CREATE TABLE public.bar(id serial primary key, bla int);
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
pg_sleep
----------
Expand All @@ -137,13 +137,12 @@ SELECT pg_sleep(1);

SELECT signal, successful, state, query, reported, pg_sleep(1)
FROM pgl_ddl_deploy.kill_blockers('cancel','public','foo');
ERROR: canceling statement due to user request
signal | successful | state | query | reported | pg_sleep
--------+------------+--------+------------------------------------------------------+----------+----------
cancel | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5); | f |
signal | successful | state | query | reported | pg_sleep
--------+------------+--------+-------------------------------------------------------+----------+----------
cancel | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30); | f |
(1 row)

\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
pg_sleep
----------
Expand All @@ -152,19 +151,14 @@ SELECT pg_sleep(1);

SELECT signal, successful, state, query, reported, pg_sleep(1)
FROM pgl_ddl_deploy.kill_blockers('terminate','public','foo');
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
signal | successful | state | query | reported | pg_sleep
-----------+------------+--------+------------------------------------------------------+----------+----------
terminate | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5); | f |
signal | successful | state | query | reported | pg_sleep
-----------+------------+--------+-------------------------------------------------------+----------+----------
terminate | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30); | f |
(1 row)

\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
-- This process should not be killed
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(2); COMMIT;" > /dev/null &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(2); COMMIT;" > /dev/null 2>&1 &
SELECT pg_sleep(1);
pg_sleep
----------
Expand Down Expand Up @@ -194,7 +188,6 @@ SELECT pgl_ddl_deploy.subscriber_command
-- This parameter is only marked TRUE for this function to be able to easily run on a provider for regression testing
p_run_anywhere := TRUE
);
ERROR: canceling statement due to user request
subscriber_command
--------------------
t
Expand All @@ -206,7 +199,7 @@ TABLE public.foo;
(0 rows)

-- Now two processes to be killed
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
pg_sleep
----------
Expand All @@ -215,7 +208,7 @@ SELECT pg_sleep(1);

-- This process will wait for the one above - but we want it to fail regardless of which gets killed first
-- Avoid it firing our event triggers by using session_replication_role = replica
\! PGOPTIONS='--client-min-messages=warning --session-replication-role=replica' psql -d contrib_regression -c "BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning --session-replication-role=replica' psql -d contrib_regression -c "BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(2);
pg_sleep
----------
Expand Down Expand Up @@ -245,16 +238,6 @@ SELECT pgl_ddl_deploy.subscriber_command
-- This parameter is only marked TRUE for this function to be able to easily run on a provider for regression testing
p_run_anywhere := TRUE
);
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
subscriber_command
--------------------
t
Expand All @@ -268,6 +251,7 @@ TABLE public.foo;
/****
Try cancel_then_terminate, which should first try to cancel
****/
-- This process should be killed
\! echo "BEGIN; SELECT * FROM public.foo;\n\! sleep 15" | psql contrib_regression > /dev/null 2>&1 &
-- This process should not be killed
\! psql contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(5); COMMIT;" > /dev/null 2>&1 &
Expand Down Expand Up @@ -322,12 +306,29 @@ DROP TABLE public.bar CASCADE;
SELECT id, signal, successful, state, query, reported
FROM pgl_ddl_deploy.killed_blockers
ORDER BY id, query;
id | signal | successful | state | query | reported
----+-----------+------------+---------------------+--------------------------------------------------------------------+----------
1 | cancel | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5); | f
2 | terminate | t | active | BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(5); | f
3 | terminate | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5); | f
4 | cancel | t | idle in transaction | SELECT * FROM public.foo; | f
5 | terminate | t | idle in transaction | SELECT * FROM public.foo; | f
id | signal | successful | state | query | reported
----+-----------+------------+---------------------+---------------------------------------------------------------------+----------
1 | cancel | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30); | f
2 | terminate | t | active | BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(30); | f
3 | terminate | t | active | BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30); | f
4 | cancel | t | idle in transaction | SELECT * FROM public.foo; | f
5 | terminate | t | idle in transaction | SELECT * FROM public.foo; | f
(5 rows)

SELECT pg_sleep(1);
pg_sleep
----------

(1 row)

-- Should be zero - everything was killed
SELECT COUNT(1)
FROM pg_stat_activity
WHERE usename = session_user
AND NOT pid = pg_backend_pid()
AND query LIKE '%public.foo%';
count
-------
0
(1 row)

23 changes: 15 additions & 8 deletions sql/25_1_5_features.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ SELECT * FROM pgl_ddl_deploy.exceptions;

CREATE TABLE public.foo(id serial primary key, bla int);
CREATE TABLE public.bar(id serial primary key, bla int);
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
SELECT signal, successful, state, query, reported, pg_sleep(1)
FROM pgl_ddl_deploy.kill_blockers('cancel','public','foo');
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
SELECT signal, successful, state, query, reported, pg_sleep(1)
FROM pgl_ddl_deploy.kill_blockers('terminate','public','foo');

\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
-- This process should not be killed
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(2); COMMIT;" > /dev/null &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(2); COMMIT;" > /dev/null 2>&1 &
SELECT pg_sleep(1);

SELECT pgl_ddl_deploy.subscriber_command
Expand Down Expand Up @@ -105,11 +105,11 @@ SELECT pgl_ddl_deploy.subscriber_command
TABLE public.foo;

-- Now two processes to be killed
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning' psql -d contrib_regression -c "BEGIN; SELECT * FROM public.foo; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(1);
-- This process will wait for the one above - but we want it to fail regardless of which gets killed first
-- Avoid it firing our event triggers by using session_replication_role = replica
\! PGOPTIONS='--client-min-messages=warning --session-replication-role=replica' psql -d contrib_regression -c "BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(5);" &
\! PGOPTIONS='--client-min-messages=warning --session-replication-role=replica' psql -d contrib_regression -c "BEGIN; ALTER TABLE public.foo DROP COLUMN bar; SELECT pg_sleep(30);" > /dev/null 2>&1 &
SELECT pg_sleep(2);

SELECT pgl_ddl_deploy.subscriber_command
Expand Down Expand Up @@ -140,11 +140,10 @@ TABLE public.foo;
/****
Try cancel_then_terminate, which should first try to cancel
****/

-- This process should be killed
\! echo "BEGIN; SELECT * FROM public.foo;\n\! sleep 15" | psql contrib_regression > /dev/null 2>&1 &

-- This process should not be killed

\! psql contrib_regression -c "BEGIN; INSERT INTO public.bar (bla) VALUES (1); SELECT pg_sleep(5); COMMIT;" > /dev/null 2>&1 &

SELECT pg_sleep(1);
Expand Down Expand Up @@ -181,3 +180,11 @@ SELECT id, signal, successful, state, query, reported
FROM pgl_ddl_deploy.killed_blockers
ORDER BY id, query;

SELECT pg_sleep(1);

-- Should be zero - everything was killed
SELECT COUNT(1)
FROM pg_stat_activity
WHERE usename = session_user
AND NOT pid = pg_backend_pid()
AND query LIKE '%public.foo%';

0 comments on commit f83ea71

Please sign in to comment.