Skip to content

Commit

Permalink
Fix flaky multi_mx_node_metadata.sql test (#7317)
Browse files Browse the repository at this point in the history
Fixes the flaky test that results in following diff:
```diff
--- /__w/citus/citus/src/test/regress/expected/multi_mx_node_metadata.out.modified	2023-11-01 14:22:12.890476575 +0000
+++ /__w/citus/citus/src/test/regress/results/multi_mx_node_metadata.out.modified	2023-11-01 14:22:12.914476657 +0000
@@ -840,24 +840,26 @@
 (1 row)

 \c :datname - - :master_port
 SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';
   datname
 ------------
  db_to_drop
 (1 row)

 DROP DATABASE db_to_drop;
+ERROR:  database "db_to_drop" is being accessed by other users
 SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';
   datname
 ------------
-(0 rows)
+ db_to_drop
+(1 row)

 -- cleanup
 DROP SEQUENCE sequence CASCADE;
 NOTICE:  drop cascades to default value for column a of table reference_table
```

(cherry picked from commit 9867c5b)
  • Loading branch information
onurctirtir authored and JelteF committed Jun 18, 2024
1 parent 4f0053e commit d963560
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/test/regress/citus_tests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ def extra_tests(self):
),
"grant_on_schema_propagation": TestDeps("minimal_schedule"),
"propagate_extension_commands": TestDeps("minimal_schedule"),
"multi_size_queries": TestDeps("base_schedule", ["multi_copy"]),
"multi_mx_node_metadata": TestDeps(
None,
[
"multi_extension",
"multi_test_helpers",
"multi_test_helpers_superuser",
],
),
}


Expand Down
21 changes: 18 additions & 3 deletions src/test/regress/expected/multi_mx_node_metadata.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SET citus.shard_count TO 8;
SET citus.shard_replication_factor TO 1;
\set VERBOSITY terse
-- Simulates a readonly node by setting default_transaction_read_only.
CREATE FUNCTION mark_node_readonly(hostname TEXT, port INTEGER, isreadonly BOOLEAN)
CREATE OR REPLACE FUNCTION mark_node_readonly(hostname TEXT, port INTEGER, isreadonly BOOLEAN)
RETURNS TEXT
LANGUAGE sql
AS $$
Expand All @@ -27,7 +27,7 @@ CREATE OR REPLACE FUNCTION raise_error_in_metadata_sync()
RETURNS void
LANGUAGE C STRICT
AS 'citus';
CREATE PROCEDURE wait_until_process_count(appname text, target_count int) AS $$
CREATE OR REPLACE PROCEDURE wait_until_process_count(appname text, target_count int) AS $$
declare
counter integer := -1;
begin
Expand Down Expand Up @@ -846,7 +846,22 @@ SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';
db_to_drop
(1 row)

DROP DATABASE db_to_drop;
DO $$
DECLARE
i int := 0;
BEGIN
WHILE NOT (SELECT bool_and(success) from run_command_on_all_nodes('DROP DATABASE IF EXISTS db_to_drop'))
LOOP
BEGIN
i := i + 1;
IF i > 5 THEN
RAISE EXCEPTION 'DROP DATABASE timed out';
END IF;
PERFORM pg_sleep(1);
END;
END LOOP;
END;
$$;
SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';
datname
---------------------------------------------------------------------
Expand Down
21 changes: 18 additions & 3 deletions src/test/regress/sql/multi_mx_node_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SET citus.shard_replication_factor TO 1;
\set VERBOSITY terse

-- Simulates a readonly node by setting default_transaction_read_only.
CREATE FUNCTION mark_node_readonly(hostname TEXT, port INTEGER, isreadonly BOOLEAN)
CREATE OR REPLACE FUNCTION mark_node_readonly(hostname TEXT, port INTEGER, isreadonly BOOLEAN)
RETURNS TEXT
LANGUAGE sql
AS $$
Expand All @@ -35,7 +35,7 @@ CREATE OR REPLACE FUNCTION raise_error_in_metadata_sync()
LANGUAGE C STRICT
AS 'citus';

CREATE PROCEDURE wait_until_process_count(appname text, target_count int) AS $$
CREATE OR REPLACE PROCEDURE wait_until_process_count(appname text, target_count int) AS $$
declare
counter integer := -1;
begin
Expand Down Expand Up @@ -378,7 +378,22 @@ SELECT trigger_metadata_sync();

SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';

DROP DATABASE db_to_drop;
DO $$
DECLARE
i int := 0;
BEGIN
WHILE NOT (SELECT bool_and(success) from run_command_on_all_nodes('DROP DATABASE IF EXISTS db_to_drop'))
LOOP
BEGIN
i := i + 1;
IF i > 5 THEN
RAISE EXCEPTION 'DROP DATABASE timed out';
END IF;
PERFORM pg_sleep(1);
END;
END LOOP;
END;
$$;

SELECT datname FROM pg_stat_activity WHERE application_name LIKE 'Citus Met%';

Expand Down

0 comments on commit d963560

Please sign in to comment.