mirror of https://github.com/citusdata/citus.git
Adds unit tests
parent
304a00ee08
commit
7ccbb848b0
|
@ -0,0 +1,53 @@
|
|||
Parsed test spec with 2 sessions
|
||||
|
||||
starting permutation: s1-begin s1-pause-node s2-begin s2-insert s2-end s1-end
|
||||
step s1-begin:
|
||||
BEGIN;
|
||||
|
||||
step s1-pause-node:
|
||||
SELECT pg_catalog.citus_pause_node(2);
|
||||
|
||||
citus_pause_node
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
step s2-begin:
|
||||
BEGIN;
|
||||
|
||||
step s2-insert:
|
||||
-- Set statement_timeout for the session (in milliseconds)
|
||||
SET statement_timeout = 1000; -- 1 seconds
|
||||
SET client_min_messages = 'notice';
|
||||
-- Variable to track if the INSERT statement was successful
|
||||
DO $$
|
||||
DECLARE
|
||||
insert_successful BOOLEAN := FALSE;
|
||||
BEGIN
|
||||
-- Execute the INSERT statement
|
||||
insert into employee values(11,'e11',3);
|
||||
-- If we reach this point, the INSERT statement was successful
|
||||
insert_successful := TRUE;
|
||||
IF insert_successful THEN
|
||||
RAISE NOTICE 'INSERT statement completed successfully. This means that citus_pause_node could not get the lock.';
|
||||
END IF;
|
||||
-- You can add additional processing here if needed
|
||||
EXCEPTION
|
||||
WHEN query_canceled THEN
|
||||
-- The INSERT statement was canceled due to timeout
|
||||
RAISE NOTICE 'query_canceled exception raised. This means that citus_pause_node was able to get the lock.';
|
||||
WHEN OTHERS THEN
|
||||
-- Any other exception raised during the INSERT statement
|
||||
RAISE;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
<waiting ...>
|
||||
step s2-insert: <... completed>
|
||||
s2: NOTICE: query_canceled exception raised. This means that citus_pause_node was able to get the lock.
|
||||
step s2-end:
|
||||
COMMIT;
|
||||
|
||||
step s1-end:
|
||||
COMMIT;
|
||||
|
|
@ -77,8 +77,10 @@ test: isolation_global_pid
|
|||
test: isolation_citus_locks
|
||||
test: isolation_reference_table
|
||||
test: isolation_schema_based_sharding
|
||||
test: isolation_citus_pause_node
|
||||
test: isolation_citus_schema_distribute_undistribute
|
||||
|
||||
|
||||
# Rebalancer
|
||||
test: isolation_blocking_move_single_shard_commands
|
||||
test: isolation_blocking_move_multi_shard_commands
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
setup
|
||||
{
|
||||
SET citus.shard_replication_factor to 1;
|
||||
|
||||
CREATE TABLE company(id int primary key, name text);
|
||||
select create_distributed_table('company', 'id');
|
||||
|
||||
create table employee(id int , name text, company_id int );
|
||||
alter table employee add constraint employee_pkey primary key (id,company_id);
|
||||
|
||||
select create_distributed_table('employee', 'company_id');
|
||||
|
||||
insert into company values(1,'c1');
|
||||
insert into company values(2,'c2');
|
||||
insert into company values(3,'c3');
|
||||
|
||||
insert into employee values(1,'e1',1);
|
||||
insert into employee values(2,'e2',1);
|
||||
insert into employee values(3,'e3',1);
|
||||
|
||||
insert into employee values(4,'e4',2);
|
||||
insert into employee values(5,'e5',2);
|
||||
insert into employee values(6,'e6',2);
|
||||
|
||||
insert into employee values(7,'e7',3);
|
||||
insert into employee values(8,'e8',3);
|
||||
insert into employee values(9,'e9',3);
|
||||
insert into employee values(10,'e10',3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
teardown
|
||||
{
|
||||
DROP TABLE company,employee;
|
||||
}
|
||||
|
||||
session "s1"
|
||||
|
||||
step "s1-begin"
|
||||
{
|
||||
BEGIN;
|
||||
}
|
||||
|
||||
step "s1-pause-node"
|
||||
{
|
||||
SELECT pg_catalog.citus_pause_node(2);
|
||||
}
|
||||
|
||||
step "s1-end"
|
||||
{
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
session "s2"
|
||||
|
||||
|
||||
step "s2-begin"
|
||||
{
|
||||
BEGIN;
|
||||
}
|
||||
|
||||
step "s2-insert"
|
||||
{
|
||||
-- Set statement_timeout for the session (in milliseconds)
|
||||
SET statement_timeout = 1000; -- 1 seconds
|
||||
SET client_min_messages = 'notice';
|
||||
|
||||
-- Variable to track if the INSERT statement was successful
|
||||
DO $$
|
||||
DECLARE
|
||||
insert_successful BOOLEAN := FALSE;
|
||||
BEGIN
|
||||
-- Execute the INSERT statement
|
||||
insert into employee values(11,'e11',3);
|
||||
|
||||
-- If we reach this point, the INSERT statement was successful
|
||||
insert_successful := TRUE;
|
||||
|
||||
IF insert_successful THEN
|
||||
RAISE NOTICE 'INSERT statement completed successfully. This means that citus_pause_node could not get the lock.';
|
||||
END IF;
|
||||
|
||||
|
||||
-- You can add additional processing here if needed
|
||||
EXCEPTION
|
||||
WHEN query_canceled THEN
|
||||
-- The INSERT statement was canceled due to timeout
|
||||
RAISE NOTICE 'query_canceled exception raised. This means that citus_pause_node was able to get the lock.';
|
||||
WHEN OTHERS THEN
|
||||
-- Any other exception raised during the INSERT statement
|
||||
RAISE;
|
||||
END;
|
||||
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
}
|
||||
|
||||
step "s2-end"
|
||||
{
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
permutation "s1-begin" "s1-pause-node" "s2-begin" "s2-insert" "s2-end" "s1-end"
|
|
@ -140,7 +140,7 @@ step "s2-commit"
|
|||
session "s3"
|
||||
|
||||
// this advisory lock with (almost) random values are only used
|
||||
// for testing purposes. For details, check Citus' logical replication
|
||||
// for testing purposes. For details, check Citus logical replication
|
||||
// source code
|
||||
step "s3-acquire-split-advisory-lock"
|
||||
{
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
setup
|
||||
{
|
||||
SELECT citus_set_coordinator_host('localhost', 57636);
|
||||
SET citus.shard_replication_factor TO 1;
|
||||
CREATE SCHEMA tenant1;
|
||||
CREATE TABLE tenant1.table1(id int PRIMARY KEY, name text, col bigint);
|
||||
INSERT INTO tenant1.table1 SELECT i, 'asd', i*1000 FROM generate_series(11, 20) i;
|
||||
|
||||
CREATE TABLE tenant1.table2(id int PRIMARY KEY, name text, col bigint);
|
||||
|
||||
CREATE TABLE public.ref(id int PRIMARY KEY);
|
||||
SELECT create_reference_table('public.ref');
|
||||
|
||||
CREATE TABLE tenant1.table3(id int PRIMARY KEY, name text, col1 int, col int REFERENCES public.ref(id));
|
||||
SELECT citus_add_local_table_to_metadata('tenant1.table3');
|
||||
}
|
||||
|
||||
teardown
|
||||
{
|
||||
DROP TABLE public.ref CASCADE;
|
||||
DROP SCHEMA IF EXISTS tenant1, tenant2 CASCADE;
|
||||
SELECT citus_remove_node('localhost', 57636);
|
||||
}
|
||||
|
||||
session "s1"
|
||||
|
||||
step "s1-begin"
|
||||
{
|
||||
BEGIN;
|
||||
SET citus.shard_replication_factor TO 1;
|
||||
}
|
||||
|
||||
step "s1-schema-distribute"
|
||||
{
|
||||
SELECT citus_schema_distribute('tenant1');
|
||||
}
|
||||
|
||||
step "s1-schema-undistribute"
|
||||
{
|
||||
SELECT citus_schema_undistribute('tenant1');
|
||||
}
|
||||
|
||||
step "s1-verify-distributed-schema"
|
||||
{
|
||||
SELECT logicalrelid, partmethod, partkey, (colocationid = (SELECT colocationid AS tenant_colocid FROM pg_dist_schema)) AS is_correct_colocid, repmodel, autoconverted FROM pg_dist_partition WHERE logicalrelid::text LIKE 'tenant%' ORDER BY logicalrelid;
|
||||
}
|
||||
|
||||
step "s1-commit"
|
||||
{
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
session "s2"
|
||||
|
||||
step "s2-drop-schema"
|
||||
{
|
||||
DROP SCHEMA tenant1 CASCADE;
|
||||
}
|
||||
|
||||
step "s2-rename-schema"
|
||||
{
|
||||
ALTER SCHEMA tenant1 RENAME TO tenant2;
|
||||
}
|
||||
|
||||
step "s2-add-table"
|
||||
{
|
||||
SET citus.shard_replication_factor TO 1;
|
||||
CREATE TABLE tenant1.table4(id int PRIMARY KEY, name text, col bigint);
|
||||
}
|
||||
|
||||
step "s2-drop-table"
|
||||
{
|
||||
DROP TABLE tenant1.table3;
|
||||
}
|
||||
|
||||
step "s2-alter-col-type"
|
||||
{
|
||||
ALTER TABLE tenant1.table3 ALTER COLUMN col1 TYPE text;
|
||||
}
|
||||
|
||||
step "s2-add-foreign-key"
|
||||
{
|
||||
ALTER TABLE tenant1.table3 ADD CONSTRAINT table3_fk1 FOREIGN KEY (id) REFERENCES tenant1.table2 (id);
|
||||
}
|
||||
|
||||
step "s2-drop-foreign-key"
|
||||
{
|
||||
ALTER TABLE tenant1.table3 DROP CONSTRAINT table3_col_fkey;
|
||||
}
|
||||
|
||||
step "s2-create-unique-index"
|
||||
{
|
||||
CREATE UNIQUE INDEX idx_2 ON tenant1.table3 (col);
|
||||
}
|
||||
|
||||
step "s2-create-unique-index-concurrently"
|
||||
{
|
||||
CREATE UNIQUE INDEX CONCURRENTLY idx_3 ON tenant1.table3 (col);
|
||||
}
|
||||
|
||||
step "s2-reindex-unique-concurrently"
|
||||
{
|
||||
REINDEX INDEX CONCURRENTLY tenant1.idx_2;
|
||||
}
|
||||
|
||||
step "s2-insert"
|
||||
{
|
||||
// we insert into public.ref table as well to prevent fkey violation
|
||||
INSERT INTO public.ref SELECT i FROM generate_series(11, 20) i;
|
||||
INSERT INTO tenant1.table3 SELECT i, 'asd', i*1000 FROM generate_series(11, 20) i;
|
||||
}
|
||||
|
||||
step "s2-delete"
|
||||
{
|
||||
DELETE FROM tenant1.table3;
|
||||
}
|
||||
|
||||
step "s2-update"
|
||||
{
|
||||
UPDATE tenant1.table3 SET col = 11 WHERE col = 11;
|
||||
}
|
||||
|
||||
// DROP SCHEMA
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-drop-schema" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-drop-schema" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// RENAME SCHEMA
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-rename-schema" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-rename-schema" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// CREATE TABLE
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-add-table" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-add-table" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// DROP TABLE
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-drop-table" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-drop-table" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// ALTER TABLE ALTER COLUMN TYPE
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-alter-col-type" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-alter-col-type" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// ADD FOREIGN KEY
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-add-foreign-key" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-add-foreign-key" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// DROP FOREIGN KEY
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-drop-foreign-key" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-drop-foreign-key" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// CREATE UNIQUE INDEX
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-create-unique-index" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-create-unique-index" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// CREATE UNIQUE INDEX CONCURRENTLY
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-create-unique-index-concurrently" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-create-unique-index-concurrently" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// REINDEX CONCURRENTLY
|
||||
permutation "s2-create-unique-index" "s1-begin" "s1-schema-distribute" "s2-reindex-unique-concurrently" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s2-create-unique-index" "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-reindex-unique-concurrently" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// INSERT
|
||||
permutation "s1-begin" "s1-schema-distribute" "s2-insert" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-insert" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// UPDATE
|
||||
permutation "s2-insert" "s1-begin" "s1-schema-distribute" "s2-update" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s2-insert" "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-update" "s1-commit" "s1-verify-distributed-schema"
|
||||
|
||||
// DELETE
|
||||
permutation "s2-insert" "s1-begin" "s1-schema-distribute" "s2-delete" "s1-commit" "s1-verify-distributed-schema"
|
||||
permutation "s2-insert" "s1-schema-distribute" "s1-begin" "s1-schema-undistribute" "s2-delete" "s1-commit" "s1-verify-distributed-schema"
|
Loading…
Reference in New Issue