Skip to content

Commit

Permalink
Merge pull request #1 from jfinzel/test_fixes
Browse files Browse the repository at this point in the history
Test fixes

* github.com:enova/pglogical_ticker:
  Update debian control file
  Handle differing behavior of WaitForBackgroundWorkerStartup in test
  Remove indeterminate sort in test 09
  • Loading branch information
Jerry Sievers committed Nov 13, 2018
2 parents 283b753 + d139070 commit 76479d1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
6 changes: 6 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Depends: postgresql-10, postgresql-10-pglogical, ${shlibs:Depends}, ${misc:Depen
Description: Have time-based replication delay for pglogical
A pglogical extension to obtain time-based replication delay for PostgreSQL 10.

Package: postgresql-11-pglogical-ticker
Architecture: any
Depends: postgresql-11, postgresql-11-pglogical, ${shlibs:Depends}, ${misc:Depends}
Description: Have time-based replication delay for pglogical
A pglogical extension to obtain time-based replication delay for PostgreSQL 11.

3 changes: 0 additions & 3 deletions debian/files

This file was deleted.

29 changes: 19 additions & 10 deletions expected/07_handlers.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
SET client_min_messages TO WARNING;
/***
There may be a race condition in WaitForBackgroundWorkerStartup that
leads to indeterminate behavior on a bad launch.

For this reason, we set log_min_messages to FATAL. These tests then
really only ensure that the server lives OK during a bad launch.
***/
SET client_min_messages TO FATAL;
--The _launch function is not supposed to be used directly
--This tests that stupid things don't do something really bad
DROP TABLE IF EXISTS bad_pid;
CREATE TEMP TABLE bad_pid AS
SELECT pglogical_ticker._launch(9999999::OID) AS pid;
ERROR: could not start background process
HINT: More details may be available in the server log.
--Verify that it exits cleanly if the SQL within the worker errors out
--In this case, renaming the function will do it
ALTER FUNCTION pglogical_ticker.tick() RENAME TO tick_oops;
SELECT pglogical_ticker.launch();
ERROR: could not start background process
HINT: More details may be available in the server log.
CONTEXT: SQL function "launch" statement 1
DROP TABLE IF EXISTS bad_pid_2;
CREATE TEMP TABLE bad_pid_2 AS
SELECT pglogical_ticker.launch() AS pid;
ALTER FUNCTION pglogical_ticker.tick_oops() RENAME TO tick;
--Verify we can't start multiple workers - the second attempt should return NULL
--We know this is imperfect but so long as pglogical_ticker.launch is not executed
Expand All @@ -36,12 +42,15 @@ SELECT pglogical_ticker.launch() IS NULL AS next_attempt_no_pid;
t
(1 row)

-- We do this because of race condition above. We may be killing more than one pid
WITH canceled AS (
SELECT pg_cancel_backend(pid)
FROM pg_stat_activity
WHERE NOT pid = pg_backend_pid()
AND query LIKE '%pglogical_ticker%';
pg_cancel_backend
-------------------
AND query LIKE '%pglogical_ticker%')
SELECT (SELECT COUNT(1) FROM canceled) > 0 AS at_least_one_canceled;
at_least_one_canceled
-----------------------
t
(1 row)

Expand Down
7 changes: 4 additions & 3 deletions expected/09_1_2_tests.out
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ SELECT pglogical_ticker.add_ticker_tables_to_replication('test1');
SELECT set_name, set_reloid
FROM pglogical_ticker.rep_set_table_wrapper() rst
INNER JOIN pglogical.replication_set rs USING (set_id)
WHERE set_name = 'test1'
INNER JOIN pg_class c ON c.oid = rst.set_reloid
-- There is a sorting indeterminacy with quoted table name. So just ignore the 'default' table
WHERE set_name = 'test1' AND c.relname <> 'default'
ORDER BY set_name, set_reloid::TEXT;
set_name | set_reloid
----------+--------------------------------------
test1 | pglogical_ticker.ddl_sql
test1 | pglogical_ticker."default"
test1 | pglogical_ticker.default_insert_only
test1 | pglogical_ticker.test1
test1 | pglogical_ticker.test10
Expand All @@ -111,7 +112,7 @@ ORDER BY set_name, set_reloid::TEXT;
test1 | pglogical_ticker.test7
test1 | pglogical_ticker.test8
test1 | pglogical_ticker.test9
(13 rows)
(12 rows)

--tables are extension members
DROP TABLE pglogical_ticker.test1;
Expand Down
21 changes: 18 additions & 3 deletions sql/07_handlers.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
SET client_min_messages TO WARNING;
/***
There may be a race condition in WaitForBackgroundWorkerStartup that
leads to indeterminate behavior on a bad launch.
For this reason, we set log_min_messages to FATAL. These tests then
really only ensure that the server lives OK during a bad launch.
***/
SET client_min_messages TO FATAL;

--The _launch function is not supposed to be used directly
--This tests that stupid things don't do something really bad
DROP TABLE IF EXISTS bad_pid;
CREATE TEMP TABLE bad_pid AS
SELECT pglogical_ticker._launch(9999999::OID) AS pid;

--Verify that it exits cleanly if the SQL within the worker errors out
--In this case, renaming the function will do it
ALTER FUNCTION pglogical_ticker.tick() RENAME TO tick_oops;
SELECT pglogical_ticker.launch();
DROP TABLE IF EXISTS bad_pid_2;
CREATE TEMP TABLE bad_pid_2 AS
SELECT pglogical_ticker.launch() AS pid;

ALTER FUNCTION pglogical_ticker.tick_oops() RENAME TO tick;

Expand All @@ -23,10 +34,14 @@ SELECT pg_sleep(1);
--Should be true
SELECT pglogical_ticker.launch() IS NULL AS next_attempt_no_pid;

-- We do this because of race condition above. We may be killing more than one pid
WITH canceled AS (
SELECT pg_cancel_backend(pid)
FROM pg_stat_activity
WHERE NOT pid = pg_backend_pid()
AND query LIKE '%pglogical_ticker%';
AND query LIKE '%pglogical_ticker%')

SELECT (SELECT COUNT(1) FROM canceled) > 0 AS at_least_one_canceled;

SELECT pg_sleep(1);
SELECT COUNT(1) AS ticker_still_running
Expand Down
4 changes: 3 additions & 1 deletion sql/09_1_2_tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ SELECT pglogical_ticker.add_ticker_tables_to_replication('test1');
SELECT set_name, set_reloid
FROM pglogical_ticker.rep_set_table_wrapper() rst
INNER JOIN pglogical.replication_set rs USING (set_id)
WHERE set_name = 'test1'
INNER JOIN pg_class c ON c.oid = rst.set_reloid
-- There is a sorting indeterminacy with quoted table name. So just ignore the 'default' table
WHERE set_name = 'test1' AND c.relname <> 'default'
ORDER BY set_name, set_reloid::TEXT;

--tables are extension members
Expand Down

0 comments on commit 76479d1

Please sign in to comment.