Skip to content

Commit 285e70b

Browse files
author
ci bot
committed
Merge branch 'fix/scheduler-shutdown-race' into 'enterprise'
fix: scheduler shutdown race — check _stopping before blocking on _reload_event See merge request dkinternal/testgen/dataops-testgen!444
2 parents 2ffaf19 + 9a0daf0 commit 285e70b

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

testgen/scheduler/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def _run(self):
122122
try:
123123
triggering_time, jobs = next(next_jobs)
124124
except StopIteration:
125-
self._reload_event.wait()
125+
if not self._stopping.is_set():
126+
self._reload_event.wait()
126127
break
127128

128129
if self._wait_until(triggering_time):

tests/unit/scheduler/test_scheduler_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def wait_for_call_count(mock, expected_count, timeout=0.5):
138138

139139
@pytest.mark.parametrize("with_job", (True, False))
140140
def test_reloads_and_shutdowns_immediately(with_job, scheduler_instance, base_time):
141-
jobs = [Job(cron_expr="0 0 * * *", cron_tz="UTC", delayed_policy=DelayedPolicy.ALL)] if with_job else []
141+
jobs = [Job(cron_expr="0 0 * * *", cron_tz="UTC", delayed_policy=DelayedPolicy.SKIP)] if with_job else []
142142
scheduler_instance.get_jobs.return_value = jobs
143143

144144
scheduler_instance.start(base_time)
@@ -169,8 +169,8 @@ def test_job_start_is_called(start_side_effect, scheduler_instance, base_time, n
169169
scheduler_instance.start(base_time)
170170

171171
for multiplier in (1, 2):
172-
while scheduler_instance.start_job.call_count != 6 * multiplier:
173-
time.sleep(0.01)
172+
assert wait_for_call_count(scheduler_instance.start_job, 6 * multiplier, timeout=5.0), \
173+
f"start_job call_count={scheduler_instance.start_job.call_count}, expected {6 * multiplier}"
174174

175175
assert scheduler_instance.get_jobs.call_count == multiplier
176176
assert get_next_mock.call_count == multiplier

0 commit comments

Comments
 (0)