diff --git a/debian/changelog b/debian/changelog index cf62e0a..dbb9116 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +pgl-ddl-deploy (1.5.1-1) unstable; urgency=medium + + * Fix test race conditions and unstable output + + -- Jeremy Finzel 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 diff --git a/expected/25_1_5_features.out b/expected/25_1_5_features.out index cc1696f..a413c5a 100644 --- a/expected/25_1_5_features.out +++ b/expected/25_1_5_features.out @@ -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 ---------- @@ -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 ---------- @@ -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 ---------- @@ -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 @@ -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 ---------- @@ -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 ---------- @@ -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 @@ -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 & @@ -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) + diff --git a/sql/25_1_5_features.sql b/sql/25_1_5_features.sql index d276130..e376c02 100644 --- a/sql/25_1_5_features.sql +++ b/sql/25_1_5_features.sql @@ -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 @@ -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 @@ -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); @@ -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%';