Skip to content

Queue::fake() does not release unique job locks between tests #58533

@mewejo

Description

@mewejo

Laravel Version

12.49.0

PHP Version

8.5.2

Database Driver & Version

Queue running via Valkey

Updated Summary

Queue::fake() intermittently fails to capture jobs dispatched via Job::dispatch(), but the behavior is no longer clearly attributable to PHP 8.5 or destructor timing changes.

Further investigation suggests the issue is more closely related to jobs implementing ShouldBeUnique, combined with persistent cache/lock state between test runs. The failure is non-deterministic: tests may pass on first execution and fail on subsequent runs unless the underlying cache (for example Redis/Valkey) is flushed. Changing the job’s uniqueId() or clearing Redis in setUp() consistently restores passing behavior.

The problem reproduces on older environments as well (PHP 8.4 with Laravel 12.27.1), indicating it likely predates the PHP 8.5 upgrade and may have gone unnoticed due to clean CI environments masking stale uniqueness locks locally.

At this point, the core issue appears to be that uniqueness locks are persisting across test runs in a way that prevents PendingDispatch::shouldDispatch() from allowing the job to be queued, causing Queue::fake() assertions to report zero dispatched jobs even though dispatch logic is executed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions