I want to verify with my test in my application logic, that model with lock can't be selected and the whole logic "around" it performs as it should.
How to do it?
I've tried to use multiple nested transactions on different connections, but it did not give any result. I still can retrieve and modify columns in the second transaction.
DB::connection('pgsql1')->transaction(function () {
factory(SomeModel::class, 5)->create();
SomeModel::inRandomOrder()->lockForUpdate()->first();
DB::connection('pgsql2')->transaction(function () {
$this->assertEquals(4, SomeModel::count()); //fails, still 5 and should be 4 due to a lock on a random model
});
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire