mirror of
https://github.com/postgres/postgres.git
synced 2026-03-05 23:04:24 -05: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
123 lines
4.7 KiB
PL/PgSQL
123 lines
4.7 KiB
PL/PgSQL
--
|
|
-- SUBSCRIPTION
|
|
--
|
|
|
|
CREATE ROLE regress_subscription_user LOGIN SUPERUSER;
|
|
CREATE ROLE regress_subscription_user2;
|
|
CREATE ROLE regress_subscription_user_dummy LOGIN NOSUPERUSER;
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user';
|
|
|
|
-- fail - no publications
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'foo';
|
|
|
|
-- fail - no connection
|
|
CREATE SUBSCRIPTION regress_testsub PUBLICATION foo;
|
|
|
|
-- fail - cannot do CREATE SUBSCRIPTION CREATE SLOT inside transaction block
|
|
BEGIN;
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'testconn' PUBLICATION testpub WITH (create_slot);
|
|
COMMIT;
|
|
|
|
-- fail - invalid connection string
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'testconn' PUBLICATION testpub;
|
|
|
|
-- fail - duplicate publications
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION foo, testpub, foo WITH (connect = false);
|
|
|
|
-- ok
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false);
|
|
|
|
COMMENT ON SUBSCRIPTION regress_testsub IS 'test subscription';
|
|
SELECT obj_description(s.oid, 'pg_subscription') FROM pg_subscription s;
|
|
|
|
-- fail - name already exists
|
|
CREATE SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false);
|
|
|
|
-- fail - must be superuser
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user2';
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION foo WITH (connect = false);
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user';
|
|
|
|
-- fail - invalid option combinations
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = false);
|
|
CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = false);
|
|
|
|
-- ok - with slot_name = NONE
|
|
CREATE SUBSCRIPTION regress_testsub3 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false);
|
|
-- fail
|
|
ALTER SUBSCRIPTION regress_testsub3 ENABLE;
|
|
ALTER SUBSCRIPTION regress_testsub3 REFRESH PUBLICATION;
|
|
|
|
DROP SUBSCRIPTION regress_testsub3;
|
|
|
|
-- fail - invalid connection string
|
|
ALTER SUBSCRIPTION regress_testsub CONNECTION 'foobar';
|
|
|
|
\dRs+
|
|
|
|
ALTER SUBSCRIPTION regress_testsub SET PUBLICATION testpub2, testpub3 WITH (refresh = false);
|
|
ALTER SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist2';
|
|
ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'newname');
|
|
|
|
-- fail
|
|
ALTER SUBSCRIPTION regress_doesnotexist CONNECTION 'dbname=regress_doesnotexist2';
|
|
ALTER SUBSCRIPTION regress_testsub SET (create_slot = false);
|
|
|
|
\dRs+
|
|
|
|
BEGIN;
|
|
ALTER SUBSCRIPTION regress_testsub ENABLE;
|
|
|
|
\dRs
|
|
|
|
ALTER SUBSCRIPTION regress_testsub DISABLE;
|
|
|
|
\dRs
|
|
|
|
COMMIT;
|
|
|
|
-- fail - must be owner of subscription
|
|
SET ROLE regress_subscription_user_dummy;
|
|
ALTER SUBSCRIPTION regress_testsub RENAME TO regress_testsub_dummy;
|
|
RESET ROLE;
|
|
|
|
ALTER SUBSCRIPTION regress_testsub RENAME TO regress_testsub_foo;
|
|
ALTER SUBSCRIPTION regress_testsub_foo SET (synchronous_commit = local);
|
|
ALTER SUBSCRIPTION regress_testsub_foo SET (synchronous_commit = foobar);
|
|
|
|
\dRs+
|
|
|
|
-- rename back to keep the rest simple
|
|
ALTER SUBSCRIPTION regress_testsub_foo RENAME TO regress_testsub;
|
|
|
|
-- fail - new owner must be superuser
|
|
ALTER SUBSCRIPTION regress_testsub OWNER TO regress_subscription_user2;
|
|
ALTER ROLE regress_subscription_user2 SUPERUSER;
|
|
-- now it works
|
|
ALTER SUBSCRIPTION regress_testsub OWNER TO regress_subscription_user2;
|
|
|
|
-- fail - cannot do DROP SUBSCRIPTION inside transaction block with slot name
|
|
BEGIN;
|
|
DROP SUBSCRIPTION regress_testsub;
|
|
COMMIT;
|
|
|
|
ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE);
|
|
|
|
-- now it works
|
|
BEGIN;
|
|
DROP SUBSCRIPTION regress_testsub;
|
|
COMMIT;
|
|
|
|
DROP SUBSCRIPTION IF EXISTS regress_testsub;
|
|
DROP SUBSCRIPTION regress_testsub; -- fail
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
DROP ROLE regress_subscription_user;
|
|
DROP ROLE regress_subscription_user2;
|
|
DROP ROLE regress_subscription_user_dummy;
|