Skip to content

Commit 861e273

Browse files
fix: resolve flaky tests by using delay=-1 for immediate job scheduling
The tests test_sigint, test_sigterm, test_suppress_dj_errors, and test_populate_exclude_error_and_ignore_jobs were flaky due to a race condition: jobs created with scheduled_time=NOW(3) might not pass the scheduled_time <= NOW(3) check if checked in the same millisecond. Fix by using delay=-1 in auto-refresh during populate(), ensuring jobs are scheduled 1 second in the past and immediately schedulable. Also update test_populate_exclude_error_and_ignore_jobs to use delay=-1 in its explicit refresh() call. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 2136ea2 commit 861e273

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/datajoint/autopopulate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ def handler(signum, frame):
485485
if refresh is None:
486486
refresh = config.jobs.auto_refresh
487487
if refresh:
488-
self.jobs.refresh(*restrictions, priority=priority)
488+
# Use delay=-1 to ensure jobs are immediately schedulable
489+
# (avoids race condition with scheduled_time <= NOW(3) check)
490+
self.jobs.refresh(*restrictions, priority=priority, delay=-1)
489491

490492
# Fetch pending jobs ordered by priority (use NOW(3) to match CURRENT_TIMESTAMP(3) precision)
491493
pending_query = self.jobs.pending & "scheduled_time <= NOW(3)"

tests/integration/test_autopopulate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def test_populate_exclude_error_and_ignore_jobs(clean_autopopulate, subject, exp
6666
assert not experiment, "table already filled?"
6767

6868
# Refresh jobs to create pending entries
69-
experiment.jobs.refresh()
69+
# Use delay=-1 to ensure jobs are immediately schedulable (avoids race condition with NOW(3))
70+
experiment.jobs.refresh(delay=-1)
7071

7172
keys = experiment.jobs.pending.keys(limit=2)
7273
for idx, key in enumerate(keys):

0 commit comments

Comments
 (0)