Skip to content

[12.x] Prevent unintended sleep on early failure of assertSequence#56583

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
xHeaven:hotfix/sleep
Aug 8, 2025
Merged

[12.x] Prevent unintended sleep on early failure of assertSequence#56583
taylorotwell merged 1 commit into
laravel:12.xfrom
xHeaven:hotfix/sleep

Conversation

@xHeaven

@xHeaven xHeaven commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

When Sleep::assertSequence is given Sleep instances as "expected" values and

  1. the count assertion fails or
  2. one of the duration checks fail (since we are going one by one via each)

the remaining Sleep objects can execute their destructors before they’ve been marked as "do not sleep".

This makes the tests run for a longer time than expected because the remaining Sleep objects will actually sleep, even though this is unintended.

Reproduction:

/**
 * Expected runtime: instant
 * Actual runtime: 3 seconds
 * Reason: in the `each` call, the first instance will fail the test, therefore
 * the second instance won't be marked as "do not sleep" - it will sleep
 */
it('will fail the first iteration', function () {
    Sleep::fake();

    Sleep::sleep(3);
    Sleep::sleep(3);

    Sleep::assertSequence([
        Sleep::sleep(3.1),
        Sleep::sleep(3),
    ]);
});

/**
 * Expected runtime: instant
 * Actual runtime: 3 seconds
 * Reason: the count assertion fails, no instance will be marked as "do not sleep" - they will sleep
 */
it('will fail the count assertion', function () {
    Sleep::fake();

    Sleep::sleep(3);
    Sleep::sleep(3);

    Sleep::assertSequence([
        Sleep::sleep(3),
    ]);
});

@xHeaven xHeaven changed the title Prevent unintended sleep on early failure of assertSequence [12.x] Prevent unintended sleep on early failure of assertSequence Aug 8, 2025
@xHeaven

xHeaven commented Aug 8, 2025

Copy link
Copy Markdown
Contributor Author

I think the failing test is unrelated to this PR, just fyi.

@taylorotwell taylorotwell merged commit fe5e22c into laravel:12.x Aug 8, 2025
42 of 62 checks passed
@xHeaven xHeaven deleted the hotfix/sleep branch August 8, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants