mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-25 21:57:33 +02:00
In commit 18555b132
we tentatively established a rule that regression
tests should use names containing "regression" for databases, and names
starting with "regress_" for all other globally-visible object names, so
as to circumscribe the side-effects that "make installcheck" could have on
an existing installation. However, no enforcement mechanism was created,
so it's unsurprising that some new violations have crept in since then.
In fact, a whole new *category* of violations has crept in, to wit we now
also have globally-visible subscription and replication origin names, and
"make installcheck" could very easily clobber user-created objects of
those types. So it's past time to do something about this.
This commit sanitizes the tests enough that they will pass (i.e. not
generate any visible warnings) with the enforcement mechanism I'll add
in the next commit. There are some TAP tests that still trigger the
warnings, but the warnings do not cause test failure. Since these tests
do not actually run against a pre-existing installation, there's no need
to worry whether they could conflict with user-created objects.
The problem with rolenames.sql testing special role names like "user"
is still there, and is dealt with only very cosmetically in this patch
(by hiding the warnings :-(). What we actually need to do to be safe is
to take that test script out of "make installcheck" altogether, but that
seems like material for a separate patch.
Discussion: https://postgr.es/m/16638.1468620817@sss.pgh.pa.us
72 lines
3.2 KiB
PL/PgSQL
72 lines
3.2 KiB
PL/PgSQL
-- predictability
|
|
SET synchronous_commit = on;
|
|
|
|
CREATE TABLE origin_tbl(id serial primary key, data text);
|
|
CREATE TABLE target_tbl(id serial primary key, data text);
|
|
|
|
SELECT pg_replication_origin_create('regress_test_decoding: regression_slot');
|
|
-- ensure duplicate creations fail
|
|
SELECT pg_replication_origin_create('regress_test_decoding: regression_slot');
|
|
|
|
--ensure deletions work (once)
|
|
SELECT pg_replication_origin_create('regress_test_decoding: temp');
|
|
SELECT pg_replication_origin_drop('regress_test_decoding: temp');
|
|
SELECT pg_replication_origin_drop('regress_test_decoding: temp');
|
|
|
|
-- various failure checks for undefined slots
|
|
select pg_replication_origin_advance('regress_test_decoding: temp', '0/1');
|
|
select pg_replication_origin_session_setup('regress_test_decoding: temp');
|
|
select pg_replication_origin_progress('regress_test_decoding: temp', true);
|
|
|
|
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
|
|
|
|
-- origin tx
|
|
INSERT INTO origin_tbl(data) VALUES ('will be replicated and decoded and decoded again');
|
|
INSERT INTO target_tbl(data)
|
|
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
|
|
|
|
-- as is normal, the insert into target_tbl shows up
|
|
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
|
|
|
|
INSERT INTO origin_tbl(data) VALUES ('will be replicated, but not decoded again');
|
|
|
|
-- mark session as replaying
|
|
SELECT pg_replication_origin_session_setup('regress_test_decoding: regression_slot');
|
|
|
|
-- ensure we prevent duplicate setup
|
|
SELECT pg_replication_origin_session_setup('regress_test_decoding: regression_slot');
|
|
|
|
SELECT '' FROM pg_logical_emit_message(false, 'test', 'this message will not be decoded');
|
|
|
|
BEGIN;
|
|
-- setup transaction origin
|
|
SELECT pg_replication_origin_xact_setup('0/aabbccdd', '2013-01-01 00:00');
|
|
INSERT INTO target_tbl(data)
|
|
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'only-local', '1');
|
|
COMMIT;
|
|
|
|
-- check replication progress for the session is correct
|
|
SELECT pg_replication_origin_session_progress(false);
|
|
SELECT pg_replication_origin_session_progress(true);
|
|
|
|
SELECT pg_replication_origin_session_reset();
|
|
|
|
SELECT local_id, external_id, remote_lsn, local_lsn <> '0/0' FROM pg_replication_origin_status;
|
|
|
|
-- check replication progress identified by name is correct
|
|
SELECT pg_replication_origin_progress('regress_test_decoding: regression_slot', false);
|
|
SELECT pg_replication_origin_progress('regress_test_decoding: regression_slot', true);
|
|
|
|
-- ensure reset requires previously setup state
|
|
SELECT pg_replication_origin_session_reset();
|
|
|
|
-- and magically the replayed xact will be filtered!
|
|
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'only-local', '1');
|
|
|
|
--but new original changes still show up
|
|
INSERT INTO origin_tbl(data) VALUES ('will be replicated');
|
|
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'only-local', '1');
|
|
|
|
SELECT pg_drop_replication_slot('regression_slot');
|
|
SELECT pg_replication_origin_drop('regress_test_decoding: regression_slot');
|