Skip to content

Commit

Permalink
Restart launcher after bgw_scheduler_restart
Browse files Browse the repository at this point in the history
If the scheduler is not restarted, it can affect other tests, so
restarting it at the end of the test.
  • Loading branch information
mkindahl committed Jan 16, 2025
1 parent 08050fb commit 75ef8ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
37 changes: 17 additions & 20 deletions tsl/test/expected/bgw_scheduler_restart.out
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ BEGIN
RAISE EXCEPTION 'backend matching % did not start before timeout', pattern;
END;
$$ LANGUAGE plpgsql;
CREATE PROCEDURE ts_terminate_launcher() AS $$
SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
$$ LANGUAGE SQL;
-- Show the default scheduler restart time
SHOW timescaledb.bgw_scheduler_restart_time;
timescaledb.bgw_scheduler_restart_time
Expand All @@ -64,12 +68,6 @@ SELECT pg_reload_conf();
t
(1 row)

SHOW timescaledb.bgw_scheduler_restart_time;
timescaledb.bgw_scheduler_restart_time
----------------------------------------
1min
(1 row)

-- Launcher is running, so we need to restart it for the scheduler
-- restart time to take effect.
SELECT datname, application_name FROM tsdb_bgw;
Expand All @@ -78,15 +76,17 @@ SELECT datname, application_name FROM tsdb_bgw;
| TimescaleDB Background Worker Launcher
(1 row)

SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
pg_terminate_backend
----------------------
t
(1 row)

CALL ts_terminate_launcher();
-- It will restart automatically, but we wait for it to start.
CALL wait_for_some_started(1, 50, '%Launcher%');
-- Make sure that the new value of the scheduler restart time is
-- correct or the rest of the tests will fail.
SHOW timescaledb.bgw_scheduler_restart_time;
timescaledb.bgw_scheduler_restart_time
----------------------------------------
10s
(1 row)

-- Verify that launcher is running. If it is not, the rest of the test
-- will fail.
SELECT datname, application_name FROM tsdb_bgw;
Expand Down Expand Up @@ -151,13 +151,7 @@ SELECT pid AS orig_pid FROM tsdb_bgw WHERE backend_type LIKE '%Launcher%' \gset
-- Kill the launcher. Since there are new restarted schedulers, the
-- handle could not be used to terminate them, and they would be left
-- running.
SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
pg_terminate_backend
----------------------
t
(1 row)

CALL ts_terminate_launcher();
-- Launcher will restart immediately, but we wait one second to give
-- it a chance to start.
CALL wait_for_some_started(1, 50, '%Launcher%');
Expand Down Expand Up @@ -189,3 +183,6 @@ SELECT _timescaledb_functions.stop_background_workers();
t
(1 row)

-- We need to restart the launcher as well to read the reset
-- configuration or it will affect other tests.
CALL ts_terminate_launcher();
21 changes: 15 additions & 6 deletions tsl/test/sql/bgw_scheduler_restart.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,29 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

CREATE PROCEDURE ts_terminate_launcher() AS $$
SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
$$ LANGUAGE SQL;

-- Show the default scheduler restart time
SHOW timescaledb.bgw_scheduler_restart_time;
ALTER SYSTEM SET timescaledb.bgw_scheduler_restart_time TO '10s';
ALTER SYSTEM SET timescaledb.debug_bgw_scheduler_exit_status TO 1;
SELECT pg_reload_conf();
SHOW timescaledb.bgw_scheduler_restart_time;

-- Launcher is running, so we need to restart it for the scheduler
-- restart time to take effect.
SELECT datname, application_name FROM tsdb_bgw;
SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
CALL ts_terminate_launcher();

-- It will restart automatically, but we wait for it to start.
CALL wait_for_some_started(1, 50, '%Launcher%');

-- Make sure that the new value of the scheduler restart time is
-- correct or the rest of the tests will fail.
SHOW timescaledb.bgw_scheduler_restart_time;

-- Verify that launcher is running. If it is not, the rest of the test
-- will fail.
SELECT datname, application_name FROM tsdb_bgw;
Expand Down Expand Up @@ -112,8 +119,7 @@ SELECT pid AS orig_pid FROM tsdb_bgw WHERE backend_type LIKE '%Launcher%' \gset
-- Kill the launcher. Since there are new restarted schedulers, the
-- handle could not be used to terminate them, and they would be left
-- running.
SELECT pg_terminate_backend(pid) FROM tsdb_bgw
WHERE backend_type LIKE '%Launcher%';
CALL ts_terminate_launcher();

-- Launcher will restart immediately, but we wait one second to give
-- it a chance to start.
Expand All @@ -131,5 +137,8 @@ SELECT (pid != :orig_pid) AS different_pid,
ALTER SYSTEM RESET timescaledb.bgw_scheduler_restart_time;
ALTER SYSTEM RESET timescaledb.debug_bgw_scheduler_exit_status;
SELECT pg_reload_conf();

SELECT _timescaledb_functions.stop_background_workers();

-- We need to restart the launcher as well to read the reset
-- configuration or it will affect other tests.
CALL ts_terminate_launcher();

0 comments on commit 75ef8ff

Please sign in to comment.