Skip to content

Commit 3619662

Browse files
committed
Stabilize bgw_job_stat_history test
Replace restarting background workers with pg_conf_reload to wake up the scheduler and avoid hard crashes of background workers.
1 parent 1a0718f commit 3619662

2 files changed

Lines changed: 34 additions & 28 deletions

File tree

tsl/test/expected/bgw_job_stat_history.out

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ SELECT scheduled FROM alter_job(:job_id_2, next_start => now());
9090
-----------
9191
t
9292

93-
SELECT _timescaledb_functions.restart_background_workers();
94-
restart_background_workers
95-
----------------------------
93+
-- Wake the scheduler so it picks up the new next_start without killing
94+
-- any in-flight worker (a hard restart races with running jobs and can
95+
-- leave an unclosed history row that surfaces as "crash detected").
96+
SELECT pg_reload_conf();
97+
pg_reload_conf
98+
----------------
9699
t
97100

98101
SELECT test.wait_for_job_to_run(:job_id_1, 2);
@@ -144,9 +147,9 @@ SELECT scheduled FROM alter_job(:job_id_2, next_start => now());
144147
-----------
145148
t
146149

147-
SELECT _timescaledb_functions.restart_background_workers();
148-
restart_background_workers
149-
----------------------------
150+
SELECT pg_reload_conf();
151+
pg_reload_conf
152+
----------------
150153
t
151154

152155
SELECT test.wait_for_job_to_run(:job_id_1, 3);
@@ -184,9 +187,9 @@ SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
184187
-----------
185188
t
186189

187-
SELECT _timescaledb_functions.restart_background_workers();
188-
restart_background_workers
189-
----------------------------
190+
SELECT pg_reload_conf();
191+
pg_reload_conf
192+
----------------
190193
t
191194

192195
SELECT test.wait_for_job_to_run(:job_id_1, 4);
@@ -219,9 +222,9 @@ SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
219222
-----------
220223
t
221224

222-
SELECT _timescaledb_functions.restart_background_workers();
223-
restart_background_workers
224-
----------------------------
225+
SELECT pg_reload_conf();
226+
pg_reload_conf
227+
----------------
225228
t
226229

227230
SELECT test.wait_for_job_to_run(:job_id_1, 5);
@@ -258,9 +261,9 @@ SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
258261
-----------
259262
t
260263

261-
SELECT _timescaledb_functions.restart_background_workers();
262-
restart_background_workers
263-
----------------------------
264+
SELECT pg_reload_conf();
265+
pg_reload_conf
266+
----------------
264267
t
265268

266269
SELECT test.wait_for_job_to_run(:job_id_1, 6);
@@ -289,9 +292,9 @@ BEGIN
289292
END
290293
$$;
291294
SELECT add_job('custom_job_alter', schedule_interval => interval '1 hour', initial_start := now()) AS job_id_3 \gset
292-
SELECT _timescaledb_functions.restart_background_workers();
293-
restart_background_workers
294-
----------------------------
295+
SELECT pg_reload_conf();
296+
pg_reload_conf
297+
----------------
295298
t
296299

297300
SELECT test.wait_for_job_to_run(:job_id_3, 1);
@@ -305,9 +308,9 @@ FROM alter_job(:job_id_3, timezone => 'America/Sao_Paulo', fixed_schedule => fal
305308
-------------------+----------------+------------------+-------------------
306309
America/Sao_Paulo | f | {"key": "value"} | @ 10 mins
307310

308-
SELECT _timescaledb_functions.restart_background_workers();
309-
restart_background_workers
310-
----------------------------
311+
SELECT pg_reload_conf();
312+
pg_reload_conf
313+
----------------
311314
t
312315

313316
SELECT test.wait_for_job_to_run(:job_id_3, 2);

tsl/test/sql/bgw_job_stat_history.sql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ SELECT pg_reload_conf();
6565
SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
6666
SELECT scheduled FROM alter_job(:job_id_2, next_start => now());
6767

68-
SELECT _timescaledb_functions.restart_background_workers();
68+
-- Wake the scheduler so it picks up the new next_start without killing
69+
-- any in-flight worker (a hard restart races with running jobs and can
70+
-- leave an unclosed history row that surfaces as "crash detected").
71+
SELECT pg_reload_conf();
6972
SELECT test.wait_for_job_to_run(:job_id_1, 2);
7073
SELECT test.wait_for_job_to_run(:job_id_2, 2);
7174

@@ -85,7 +88,7 @@ SELECT scheduled FROM alter_job(:job_id_2, config => '{"bar": 1}'::jsonb);
8588
SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
8689
SELECT scheduled FROM alter_job(:job_id_2, next_start => now());
8790

88-
SELECT _timescaledb_functions.restart_background_workers();
91+
SELECT pg_reload_conf();
8992
SELECT test.wait_for_job_to_run(:job_id_1, 3);
9093
SELECT test.wait_for_job_to_run(:job_id_2, 3);
9194

@@ -98,7 +101,7 @@ ORDER BY id, job_id;
98101
-- Changing the config of one job
99102
SELECT scheduled FROM alter_job(:job_id_1, config => '{"foo": 2, "bar": 1}'::jsonb);
100103
SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
101-
SELECT _timescaledb_functions.restart_background_workers();
104+
SELECT pg_reload_conf();
102105
SELECT test.wait_for_job_to_run(:job_id_1, 4);
103106

104107
-- Check job execution history
@@ -118,7 +121,7 @@ $$;
118121

119122
-- Run the job
120123
SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
121-
SELECT _timescaledb_functions.restart_background_workers();
124+
SELECT pg_reload_conf();
122125
SELECT test.wait_for_job_to_run(:job_id_1, 5);
123126

124127
-- Check job execution history
@@ -141,7 +144,7 @@ $$;
141144

142145
-- Run the job
143146
SELECT scheduled FROM alter_job(:job_id_1, next_start => now());
144-
SELECT _timescaledb_functions.restart_background_workers();
147+
SELECT pg_reload_conf();
145148
SELECT test.wait_for_job_to_run(:job_id_1, 6);
146149

147150
-- Check job execution history
@@ -159,12 +162,12 @@ END
159162
$$;
160163

161164
SELECT add_job('custom_job_alter', schedule_interval => interval '1 hour', initial_start := now()) AS job_id_3 \gset
162-
SELECT _timescaledb_functions.restart_background_workers();
165+
SELECT pg_reload_conf();
163166
SELECT test.wait_for_job_to_run(:job_id_3, 1);
164167

165168
SELECT timezone, fixed_schedule, config, schedule_interval
166169
FROM alter_job(:job_id_3, timezone => 'America/Sao_Paulo', fixed_schedule => false, config => '{"key": "value"}'::jsonb, schedule_interval => interval '10 min', next_start => now());
167-
SELECT _timescaledb_functions.restart_background_workers();
170+
SELECT pg_reload_conf();
168171
SELECT test.wait_for_job_to_run(:job_id_3, 2);
169172

170173
-- Should return two executions, the second will show the changed values

0 commit comments

Comments
 (0)