-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Potential race condition with model factory after callbacks #23621
Comments
|
Re-opening ... looks like this might be a race condition. I'm getting varied results even when just re-running the same tests repeatedly. I'm not sure if I can put together a test that is 100% reproducible though. Does this make sense to others that a race could be happening here? I'm running tests with in-memory sqlite. |
It might be a sqlite quirk can you try mysql? |
I've just encountered an issue myself that seems very similar. Consider the following test:
The intent of the test is fairly self-evident. I've written a custom scope called
This test fails or passes randomly, on the assertion: I'm running my tests on an in-memory SQLite database, just like @Indemnity83. Notably, I have an entire test suite that runs predictably. This is the first time I've encountered this behaviour. Unlike @Indemnity83, I do not have an existing entity that I can call PS: As a truly blunt debug, I tried adding PPS: Despite the random behaviour of my custom scope, PPPS: After switching from using the factory to just using |
@tillkruss Why was this closed? |
Same problem here. I have to |
I know the issue is closed, but I still wanted to mention that I'm getting this behaviour now. |
Description:
It looks like I introduced an unexpected bug/race condition with the behavior of after callbacks in PR #23495. In that the model returned can become out of sync with the database state that was created inside the factory()->create() call.
Steps To Reproduce:
Assuming you have users and teams:
Example after callback for a user, who must be a member of a team to be a valid user:
In a test, the first test assertion will unexpectedly fail sometimes, but the second (after calling fresh()) will always pass.
The text was updated successfully, but these errors were encountered: