Skip to content

Commit

Permalink
Use DROP DATABASE ... WITH (FORCE) on tests
Browse files Browse the repository at this point in the history
PG13 introduced an option to DROP DATABASE statement to terminate all
existing connections to the target database. Now that our minor
supported version is PG13 make sense to use it on regression tests in
order to avoid potential flaky tests.
  • Loading branch information
fabriziomello committed Sep 26, 2023
1 parent 727a027 commit 0ae6f95
Show file tree
Hide file tree
Showing 113 changed files with 355 additions and 359 deletions.
8 changes: 4 additions & 4 deletions test/expected/bgw_launcher.out
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ SELECT wait_worker_counts(1,1,1,0);
t
(1 row)

DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);
-- Now the db_scheduler for test db should have disappeared
SELECT wait_worker_counts(1,0,1,0);
wait_worker_counts
Expand Down Expand Up @@ -534,7 +534,7 @@ SELECT wait_worker_counts(1,1,0,0);
t
(1 row)

DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);
-- Now make sure that there's no race between create database and create extension.
-- Although to be honest, this race probably wouldn't manifest in this test.
\c template1
Expand Down Expand Up @@ -566,7 +566,7 @@ SELECT wait_for_bgw_scheduler('db_rename_test');

ALTER DATABASE db_rename_test RENAME TO db_rename_test2;
WARNING: you need to manually restart any running background workers after this command
DROP DATABASE db_rename_test2;
DROP DATABASE db_rename_test2 WITH (FORCE);
-- test create database with timescaledb database as template
SELECT wait_for_bgw_scheduler(:'TEST_DBNAME');
wait_for_bgw_scheduler
Expand All @@ -581,7 +581,7 @@ SELECT wait_for_bgw_scheduler(:'TEST_DBNAME');
BGW Scheduler found.
(1 row)

DROP DATABASE db_from_template;
DROP DATABASE db_from_template WITH (FORCE);
-- test alter database set tablespace
SET client_min_messages TO error;
DROP TABLESPACE IF EXISTS tablespace1;
Expand Down
2 changes: 1 addition & 1 deletion test/expected/drop_owned.out
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ CREATE database test_drop_owned;
\c test_drop_owned
DROP OWNED BY :ROLE_SUPERUSER;
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE test_drop_owned;
DROP DATABASE test_drop_owned WITH (FORCE);
-- Test that dependencies on roles are added to chunks when creating
-- new chunks. If that is not done, DROP OWNED BY will not revoke the
-- privilege on the chunk.
Expand Down
2 changes: 1 addition & 1 deletion test/expected/loader-oss.out
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,6 @@ WARNING: mock init "mock-2"

-- clean up additional database
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE :"TEST_DBNAME_2";
DROP DATABASE :"TEST_DBNAME_2" WITH (FORCE);
WARNING: mock init "mock-2"
WARNING: mock post_analyze_hook "mock-2"
2 changes: 1 addition & 1 deletion test/expected/loader-tsl.out
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ WARNING: mock post_analyze_hook "mock-2"
NOTICE: OSM-mock-1 got DROP TABLE 'test'
-- clean up additional database
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE :"TEST_DBNAME_2";
DROP DATABASE :"TEST_DBNAME_2" WITH (FORCE);
WARNING: mock init "mock-2"
WARNING: mock post_analyze_hook "mock-2"
WARNING: OSM-mock-1 _PG_init
4 changes: 1 addition & 3 deletions test/expected/pg_dump.out
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,4 @@ SELECT * FROM test_tz ORDER BY time;
(4 rows)

\c :TEST_DBNAME :ROLE_SUPERUSER
-- DROP DATABASE WITH(FORCE) is only available in PG13+
SELECT CASE WHEN current_setting('server_version_num')::int/10000 >= 13 THEN 'WITH(FORCE)' ELSE '' END AS "DROPDBOPTION" \gset
DROP DATABASE :TEST_DBNAME_EXTRA :DROPDBOPTION;
DROP DATABASE :TEST_DBNAME_EXTRA WITH (FORCE);
2 changes: 1 addition & 1 deletion test/expected/pg_dump_unprivileged.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ CREATE database dump_unprivileged;
\! utils/pg_dump_unprivileged.sh
\c template1 :ROLE_SUPERUSER
DROP EXTENSION timescaledb;
DROP DATABASE dump_unprivileged;
DROP DATABASE dump_unprivileged WITH (FORCE);
DROP USER dump_unprivileged;
2 changes: 1 addition & 1 deletion test/expected/relocate_extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- results are compared
\set QUERY_RESULT_TEST_EQUAL_RELPATH 'include/query_result_test_equal.sql'
\c postgres :ROLE_SUPERUSER
DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);
CREATE DATABASE :TEST_DBNAME;
\c :TEST_DBNAME
CREATE SCHEMA "testSchema0";
Expand Down
2 changes: 1 addition & 1 deletion test/expected/truncate.out
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ TRUNCATE TABLE test_hypertable;
\c :TEST_DBNAME :ROLE_SUPERUSER
-- set client_min_messages to ERROR to suppress warnings about orphaned files
SET client_min_messages TO ERROR;
DROP DATABASE test_trunc_ht;
DROP DATABASE test_trunc_ht WITH (FORCE);
DROP ROLE owner;
DROP ROLE truncator;
2 changes: 1 addition & 1 deletion test/expected/trusted_extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ SELECT * FROM timescaledb_information.hypertables;
DROP EXTENSION timescaledb CASCADE;
NOTICE: drop cascades to 3 other objects
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE trusted_test;
DROP DATABASE trusted_test WITH (FORCE);
8 changes: 4 additions & 4 deletions test/sql/bgw_launcher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE EXTENSION timescaledb CASCADE;
RESET client_min_messages;
SELECT wait_worker_counts(1,1,1,0);

DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);

-- Now the db_scheduler for test db should have disappeared
SELECT wait_worker_counts(1,0,1,0);
Expand Down Expand Up @@ -216,7 +216,7 @@ SELECT wait_worker_counts(1,0,0,0);
-- Make sure we see a scheduler start.
CREATE DATABASE :TEST_DBNAME;
SELECT wait_worker_counts(1,1,0,0);
DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);
-- Now make sure that there's no race between create database and create extension.
-- Although to be honest, this race probably wouldn't manifest in this test.
\c template1
Expand All @@ -239,13 +239,13 @@ CREATE EXTENSION timescaledb;
\c :TEST_DBNAME_2 :ROLE_SUPERUSER
SELECT wait_for_bgw_scheduler('db_rename_test');
ALTER DATABASE db_rename_test RENAME TO db_rename_test2;
DROP DATABASE db_rename_test2;
DROP DATABASE db_rename_test2 WITH (FORCE);

-- test create database with timescaledb database as template
SELECT wait_for_bgw_scheduler(:'TEST_DBNAME');
CREATE DATABASE db_from_template WITH TEMPLATE :TEST_DBNAME;
SELECT wait_for_bgw_scheduler(:'TEST_DBNAME');
DROP DATABASE db_from_template;
DROP DATABASE db_from_template WITH (FORCE);

-- test alter database set tablespace
SET client_min_messages TO error;
Expand Down
2 changes: 1 addition & 1 deletion test/sql/drop_owned.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CREATE database test_drop_owned;
\c test_drop_owned
DROP OWNED BY :ROLE_SUPERUSER;
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE test_drop_owned;
DROP DATABASE test_drop_owned WITH (FORCE);

-- Test that dependencies on roles are added to chunks when creating
-- new chunks. If that is not done, DROP OWNED BY will not revoke the
Expand Down
2 changes: 1 addition & 1 deletion test/sql/loader.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ DROP TABLE test;

-- clean up additional database
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE :"TEST_DBNAME_2";
DROP DATABASE :"TEST_DBNAME_2" WITH (FORCE);
4 changes: 1 addition & 3 deletions test/sql/pg_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,5 @@ SELECT * FROM test_tz ORDER BY time;

\c :TEST_DBNAME :ROLE_SUPERUSER

-- DROP DATABASE WITH(FORCE) is only available in PG13+
SELECT CASE WHEN current_setting('server_version_num')::int/10000 >= 13 THEN 'WITH(FORCE)' ELSE '' END AS "DROPDBOPTION" \gset
DROP DATABASE :TEST_DBNAME_EXTRA :DROPDBOPTION;
DROP DATABASE :TEST_DBNAME_EXTRA WITH (FORCE);

2 changes: 1 addition & 1 deletion test/sql/pg_dump_unprivileged.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ CREATE database dump_unprivileged;

\c template1 :ROLE_SUPERUSER
DROP EXTENSION timescaledb;
DROP DATABASE dump_unprivileged;
DROP DATABASE dump_unprivileged WITH (FORCE);
DROP USER dump_unprivileged;

2 changes: 1 addition & 1 deletion test/sql/relocate_extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
\set QUERY_RESULT_TEST_EQUAL_RELPATH 'include/query_result_test_equal.sql'

\c postgres :ROLE_SUPERUSER
DROP DATABASE :TEST_DBNAME;
DROP DATABASE :TEST_DBNAME WITH (FORCE);
CREATE DATABASE :TEST_DBNAME;

\c :TEST_DBNAME
Expand Down
2 changes: 1 addition & 1 deletion test/sql/truncate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ TRUNCATE TABLE test_hypertable;
\c :TEST_DBNAME :ROLE_SUPERUSER
-- set client_min_messages to ERROR to suppress warnings about orphaned files
SET client_min_messages TO ERROR;
DROP DATABASE test_trunc_ht;
DROP DATABASE test_trunc_ht WITH (FORCE);
DROP ROLE owner;
DROP ROLE truncator;
2 changes: 1 addition & 1 deletion test/sql/trusted_extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ SELECT * FROM timescaledb_information.hypertables;
DROP EXTENSION timescaledb CASCADE;

\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE trusted_test;
DROP DATABASE trusted_test WITH (FORCE);
2 changes: 1 addition & 1 deletion test/sql/updates/cleanup.multinode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

DROP TABLE disthyper;
SELECT delete_data_node('dn1');
drop database if exists dn1;
drop database if exists dn1 with (force);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_bgw_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,6 @@ SELECT count(*) FROM _timescaledb_config.bgw_job

-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_ddl_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,6 @@ WHERE d.hypertable_id = ca.mat_hypertable_id;

-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_invalidation_dist_ht-13.out
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,6 @@ DETAIL: Expected an integer but current value is "-".
\set VERBOSITY terse
-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_invalidation_dist_ht-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,6 @@ DETAIL: Expected an integer but current value is "-".
\set VERBOSITY terse
-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_invalidation_dist_ht-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,6 @@ DETAIL: Expected an integer but current value is "-".
\set VERBOSITY terse
-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_migrate_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,6 @@ psql:include/cagg_migrate_common.sql:374: NOTICE: drop cascades to 6 other obje
DROP TABLE conditions;
-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_on_cagg_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -5884,6 +5884,6 @@ psql:include/cagg_on_cagg_validations.sql:86: NOTICE: materialized view "condit
DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL;
-- Cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
6 changes: 3 additions & 3 deletions tsl/test/expected/cagg_on_cagg_joins_dist_ht.out
Original file line number Diff line number Diff line change
Expand Up @@ -5532,6 +5532,6 @@ psql:include/cagg_on_cagg_validations.sql:86: NOTICE: materialized view "condit
DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL;
-- Cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
4 changes: 2 additions & 2 deletions tsl/test/expected/chunk_api.out
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ WARNING: insufficient number of data nodes for distributed hypertable "disttabl
t
(1 row)

DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
-- Test create_chunk_table to recreate the chunk table and show dimension slices
SET ROLE :ROLE_DEFAULT_PERM_USER;
SELECT * FROM chunkapi ORDER BY time;
Expand Down
6 changes: 3 additions & 3 deletions tsl/test/expected/chunk_utils_internal.out
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,6 @@ ERROR: Cannot insert into tiered chunk range of public.osm_slice_update - attem
\set ON_ERROR_STOP 1
-- clean up databases created
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE postgres_fdw_db;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE postgres_fdw_db WITH (FORCE);
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
2 changes: 1 addition & 1 deletion tsl/test/expected/compression_update_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ ERROR: UPDATE/DELETE is disabled on compressed chunks
--github issue: 5586
--testcase with multiple indexes
\c :TEST_DBNAME :ROLE_SUPERUSER
DROP DATABASE IF EXISTS test;
DROP DATABASE IF EXISTS test WITH (FORCE);
NOTICE: database "test" does not exist, skipping
CREATE DATABASE test;
\c test :ROLE_SUPERUSER
Expand Down
6 changes: 3 additions & 3 deletions tsl/test/expected/data_fetcher.out
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ EXPLAIN (COSTS) SELECT * FROM one_batch;
(1 row)

RESET ROLE;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
DROP DATABASE :DATA_NODE_1 WITH (FORCE);
DROP DATABASE :DATA_NODE_2 WITH (FORCE);
DROP DATABASE :DATA_NODE_3 WITH (FORCE);
28 changes: 14 additions & 14 deletions tsl/test/expected/data_node.out
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ SELECT * FROM hypertable_partitions;
-- Cleanup databases
RESET ROLE;
SET client_min_messages TO ERROR;
DROP DATABASE :DN_DBNAME_1;
DROP DATABASE :DN_DBNAME_2;
DROP DATABASE :DN_DBNAME_3;
DROP DATABASE :DN_DBNAME_1 WITH (FORCE);
DROP DATABASE :DN_DBNAME_2 WITH (FORCE);
DROP DATABASE :DN_DBNAME_3 WITH (FORCE);
SET client_min_messages TO INFO;
SELECT node_name, database, node_created, database_created, extension_created FROM add_data_node('data_node_1', host => 'localhost', database => :'DN_DBNAME_1');
node_name | database | node_created | database_created | extension_created
Expand Down Expand Up @@ -868,10 +868,10 @@ SELECT * FROM create_distributed_hypertable('disttable', 'time');
ERROR: no data nodes can be assigned to the hypertable
\set ON_ERROR_STOP 1
-- These data nodes have been deleted, so safe to remove their databases.
DROP DATABASE :DN_DBNAME_1;
DROP DATABASE :DN_DBNAME_2;
DROP DATABASE :DN_DBNAME_3;
DROP DATABASE :DN_DBNAME_4;
DROP DATABASE :DN_DBNAME_1 WITH (FORCE);
DROP DATABASE :DN_DBNAME_2 WITH (FORCE);
DROP DATABASE :DN_DBNAME_3 WITH (FORCE);
DROP DATABASE :DN_DBNAME_4 WITH (FORCE);
-- there should be no data nodes
SELECT node_name FROM timescaledb_information.data_nodes ORDER BY node_name;
node_name
Expand Down Expand Up @@ -1521,7 +1521,7 @@ ERROR: function add_data_node(unknown) does not exist at character 15
-- establish connection to a data node.
--
RESET ROLE;
DROP DATABASE :DN_DBNAME_1;
DROP DATABASE :DN_DBNAME_1 WITH (FORCE);
CREATE DATABASE :DN_DBNAME_1 OWNER :ROLE_1;
\c :DN_DBNAME_1
CREATE SCHEMA _timescaledb_functions;
Expand Down Expand Up @@ -1607,12 +1607,12 @@ SELECT * FROM delete_data_node('data_node_6');
(1 row)

RESET ROLE;
DROP DATABASE :DN_DBNAME_1;
DROP DATABASE :DN_DBNAME_2;
DROP DATABASE :DN_DBNAME_3;
DROP DATABASE :DN_DBNAME_4;
DROP DATABASE :DN_DBNAME_5;
DROP DATABASE :DN_DBNAME_6;
DROP DATABASE :DN_DBNAME_1 WITH (FORCE);
DROP DATABASE :DN_DBNAME_2 WITH (FORCE);
DROP DATABASE :DN_DBNAME_3 WITH (FORCE);
DROP DATABASE :DN_DBNAME_4 WITH (FORCE);
DROP DATABASE :DN_DBNAME_5 WITH (FORCE);
DROP DATABASE :DN_DBNAME_6 WITH (FORCE);
-----------------------------------------------
-- Test alter_data_node()
-----------------------------------------------
Expand Down
Loading

0 comments on commit 0ae6f95

Please sign in to comment.