Skip to content

Commit

Permalink
add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onurctirtir committed Feb 21, 2024
1 parent 18d6cb0 commit 146a685
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
115 changes: 115 additions & 0 deletions src/test/regress/expected/other_databases.out
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,122 @@ SELECT * FROM public.check_database_on_all_nodes('other_db4') ORDER BY node_type
(3 rows)

DROP DATABASE worker_other_db;
CREATE DATABASE other_db5;
-- disable create database propagation for the next test
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
result
---------------------------------------------------------------------
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
(3 rows)

SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
result
---------------------------------------------------------------------
t
t
t
(3 rows)

SELECT pg_sleep(0.1);
pg_sleep
---------------------------------------------------------------------

(1 row)

\c other_db5 - - :worker_2_port
-- locally create a database
CREATE DATABASE local_db;
\c regression - - -
-- re-enable create database propagation
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO true$$);
result
---------------------------------------------------------------------
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
(3 rows)

SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
result
---------------------------------------------------------------------
t
t
t
(3 rows)

SELECT pg_sleep(0.1);
pg_sleep
---------------------------------------------------------------------

(1 row)

\c other_db5 - - :master_port
-- Test a scenario where create database fails because the database
-- already exists on another node and we don't crash etc.
CREATE DATABASE local_db;
ERROR: database "local_db" already exists
CONTEXT: while executing command on localhost:xxxxx
while executing command on localhost:xxxxx
\c regression - - -
SELECT * FROM public.check_database_on_all_nodes('local_db') ORDER BY node_type, result;
node_type | result
---------------------------------------------------------------------
coordinator (local) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
worker node (remote) | {"database_properties": {"datacl": null, "datname": "local_db", "datctype": "C", "encoding": "UTF8", "datcollate": "C", "tablespace": "pg_default", "daticurules": null, "datallowconn": true, "datconnlimit": -1, "daticulocale": null, "datistemplate": false, "database_owner": "postgres", "datcollversion": null, "datlocprovider": "c"}, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false}
(3 rows)

\c - - - :worker_2_port
-- locally drop the database for cleanup purposes
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
result
---------------------------------------------------------------------
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
(3 rows)

SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
result
---------------------------------------------------------------------
t
t
t
(3 rows)

SELECT pg_sleep(0.1);
pg_sleep
---------------------------------------------------------------------

(1 row)

DROP DATABASE local_db;
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO true$$);
result
---------------------------------------------------------------------
ALTER SYSTEM
ALTER SYSTEM
ALTER SYSTEM
(3 rows)

SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
result
---------------------------------------------------------------------
t
t
t
(3 rows)

SELECT pg_sleep(0.1);
pg_sleep
---------------------------------------------------------------------

(1 row)

\c - - - :master_port
DROP DATABASE other_db5;
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
result
---------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions src/test/regress/sql/other_databases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,53 @@ DROP DATABASE other_db4;
SELECT * FROM public.check_database_on_all_nodes('other_db4') ORDER BY node_type;

DROP DATABASE worker_other_db;

CREATE DATABASE other_db5;

-- disable create database propagation for the next test
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
SELECT pg_sleep(0.1);

\c other_db5 - - :worker_2_port

-- locally create a database
CREATE DATABASE local_db;

\c regression - - -

-- re-enable create database propagation
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO true$$);
SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
SELECT pg_sleep(0.1);

\c other_db5 - - :master_port

-- Test a scenario where create database fails because the database
-- already exists on another node and we don't crash etc.
CREATE DATABASE local_db;

\c regression - - -

SELECT * FROM public.check_database_on_all_nodes('local_db') ORDER BY node_type, result;

\c - - - :worker_2_port

-- locally drop the database for cleanup purposes
SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
SELECT pg_sleep(0.1);

DROP DATABASE local_db;

SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO true$$);
SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
SELECT pg_sleep(0.1);

\c - - - :master_port

DROP DATABASE other_db5;

SELECT result FROM run_command_on_all_nodes($$ALTER SYSTEM SET citus.enable_create_database_propagation TO false$$);
SELECT result FROM run_command_on_all_nodes($$SELECT pg_reload_conf()$$);
SELECT pg_sleep(0.1);
Expand Down

0 comments on commit 146a685

Please sign in to comment.