Repository navigation
Conversation
Factory jobs share one compile-time organization id. Job.enqueue/finish/ stop spawn an unlinked scheduler process that, ~100ms later, locks every enqueued job of that organization FOR UPDATE. When it outlives the test that spawned it, it locks the next test's rows, and TaskFailFast.query (FOR UPDATE SKIP LOCKED) skips them, so ".query when the strategy is cancel" sometimes returns 2 jobs instead of 3. Give each test its own organization id so leftover scheduler processes cannot lock its jobs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Fixes a flaky test:
Zebra.Workers.TaskFailFastTest".query when the strategy is cancel => return all non-started jobs" sometimes fails withassert length(tuples) == 3(left: 2).Cause. Every job created by
Support.Factories.Jobuses the same compile-time organization id.Job.enqueue,finish,stopandforce_finishcallScheduler.lock_and_process_async/1, which spawns an unlinked process. About 100ms later that process locks every enqueued job of the organizationFOR UPDATEand holds the lock while it loads the org. When it outlives the test that spawned it, it locks the next test's rows.TaskFailFast.query/1usesFOR UPDATE ... SKIP LOCKED, so it leaves the locked job out. In the failing CI log, the scheduler's selection query runs between the test's inserts and its query.Production behaves correctly here:
SKIP LOCKEDis intended, and the worker picks up skipped jobs on its next tick, about a second later. Only the tests share state.Change. Test-only. Each test gets its own organization id, and its jobs are created through a small
create_job/3helper that sets it. Leftover scheduler processes can no longer lock this test's jobs. Production code is unchanged.For reviewers. The root cause is in the test harness: processes spawned with
spawn/1inlock_and_process_async/1can outlive their test, and theDataCasetruncates don't stop them. Fixing that globally would mean running those tasks under aTask.Supervisorand stopping its children inDataCasesetup. That is left out of this PR on purpose.✅ Checklist
make format.exandmake lint.exare clean