[12.x] ShouldBeUnique Does Not Universally Prevent Duplicates #51833
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.
Fixes #51798
This fix was suggested in the original PR which introduced
ShouldBeUnique
here. Specifically pulled inspiration from the gist linked in the comments of that PR.I pulled the logic for
shouldDispatch()
from the prexisting method in thePendingDispatch
class. However I noticed in #39302 that an additionalCheck was added before attempting to acquire a lock. I'm not sure if checking for this should be done here?
I also wasn't quite sure the best way to write tests for this (or where best to put them), as the logic is buried pretty deep into the
Queue
class and required a lot of mocks. I wrote a couple as a proof of concept, but would improve/add more if necessary (suggestions/help welcome).Also potentially of note is that the
shouldDispatch
check happens during the callback forShouldQueueAfterCommit
jobs. This means that the uniqueness is checked after the transaction, not immediately. I would think this behavior is desired, but I'm not quite sureLastly, this is a breaking change, as it prevents jobs from being queued sometimes when they previously would have been, therefore I've opened the PR to master
NOTE: Removed
testUniqueJobsAreNotDispatched
as it seems like a faulty test to me? It's essentially dispatching the job unto theBusFake
(which never executes the job, since it's a fake), attempting to run the job with the queue worker, then asserting that the job lock still exists. But if the job has already run (or run synchronously), the lock should have already been released