diff --git a/src/test/regress/citus_tests/test/test_maintenancedeamon.py b/src/test/regress/citus_tests/test/test_maintenancedeamon.py index 3b4b16eb0..bf1a48b19 100644 --- a/src/test/regress/citus_tests/test/test_maintenancedeamon.py +++ b/src/test/regress/citus_tests/test/test_maintenancedeamon.py @@ -5,7 +5,7 @@ import time -def wait_until_deamons_start(deamoncount, cluster): +def wait_until_maintenance_deamons_start(deamoncount, cluster): i = 0 n = 0 @@ -26,13 +26,17 @@ def wait_until_deamons_start(deamoncount, cluster): def test_set_maindb(cluster_factory): cluster = cluster_factory(0) + # Test that once citus.main_db is set to a database name + # there are two maintenance deamons running upon restart. + # One maintenance deamon for the database of the current connection + # and one for the citus.main_db. cluster.coordinator.create_database("mymaindb") cluster.coordinator.configure("citus.main_db='mymaindb'") cluster.coordinator.restart() assert cluster.coordinator.sql_value("SHOW citus.main_db;") == "mymaindb" - wait_until_deamons_start(2, cluster) + wait_until_maintenance_deamons_start(2, cluster) assert ( cluster.coordinator.sql_value( @@ -41,10 +45,32 @@ def test_set_maindb(cluster_factory): == 1 ) + # Test that once citus.main_db is set to empty string + # there is only one maintenance deamon for the database + # of the current connection. cluster.coordinator.configure("citus.main_db=''") cluster.coordinator.restart() assert cluster.coordinator.sql_value("SHOW citus.main_db;") == "" - wait_until_deamons_start(1, cluster) + wait_until_maintenance_deamons_start(1, cluster) + + # Test that after citus.main_db is dropped. The maintenance + # deamon for this database is terminated. + cluster.coordinator.configure("citus.main_db='mymaindb'") + cluster.coordinator.restart() + assert cluster.coordinator.sql_value("SHOW citus.main_db;") == "mymaindb" + + wait_until_maintenance_deamons_start(2, cluster) + + cluster.coordinator.sql("DROP DATABASE mymaindb;") + + wait_until_maintenance_deamons_start(1, cluster) + + assert ( + cluster.coordinator.sql_value( + "SELECT count(*) FROM pg_stat_activity WHERE application_name = 'Citus Maintenance Daemon' AND datname='mymaindb';" + ) + == 0 + ) cluster.coordinator.cleanup_databases()