dimanche 30 septembre 2018

Laravel 5.6. How test racing conditions occurred during lockForUpdate()

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
    });
});



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zGClO8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire