You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to write a test that may recreate a race condition and test how the app behaves in this situation.
Example:
test('it behaves', function () {
$slot = Slot::factory()->create(['remaining' => 1]);
$s = newSlotService;
$hold1 = $s->createHold($slot);
$hold2 = $s->createHold($slot);
// here I run `$s->confirmHold($hold1)` and `$s->confirmHold($hold2)` in parallel// here I assert only one of those holds was actually confirmed.
});
I've tried doing so by using Concurrency::run(), Http::pool() and even with nunomaduro/pokio, but nothing worked.
The main issue, If I remember correctly, was that in each of those processes I had like a separate copy of database (in each, slot.remaining was equal 1 and no locks encountered).
What would be the proper way to test handling of race conditions in Laravel?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm trying to write a test that may recreate a race condition and test how the app behaves in this situation.
Example:
I've tried doing so by using
Concurrency::run(),Http::pool()and even withnunomaduro/pokio, but nothing worked.The main issue, If I remember correctly, was that in each of those processes I had like a separate copy of database (in each, slot.remaining was equal 1 and no locks encountered).
What would be the proper way to test handling of race conditions in Laravel?
Beta Was this translation helpful? Give feedback.
All reactions