Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

xHeaven
Copy link
Contributor

@xHeaven xHeaven commented Aug 8, 2025

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
Copy link
Contributor Author

xHeaven commented Aug 8, 2025

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