Closed ChoKaPeek closed 3 years ago
Hey there,
Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out and re-open this issue.
Thanks!
We are experiencing similar problem in our pipelines. Running multiple parallel tests, which are using transactions often causes PDO exception.
I've debugged it havely and have suspicion that the cause is shared db session when running transactions from command line. Parallel tests create separate processes per file, so if one file is smaller than the other the process is finishing when the other process is in transaction mode at the time.
PHP process, when closing clears all open connections by default and it looks like it clears transactions as well. I still cannot create a single code to have it replicated all the time, but for our app almost every attempt ends with PDO exception for inactive transaction.
Ref: stackoverflow
Description:
Greetings, we want to test multiple database interactions, so we need isolated tests and a way to create / migrate / seed replicas of our mysql database (disk storage). We are using Sanctum for authentication.
I've been trying to use the new parallel testing functionality and read your different docs and issues about it.
My conclusions are:
My seeds are a bunch of factories, DB::unprepared.
Running
art migrate:fresh
andart db:seed
manually thenart test
without--parallel
, tests work fine. However when running with--parallel --recreate-databases
, the seeding does not work and I stumble upon this error:Time: 00:14.187, Memory: 20.00 MB
There were 2 errors:
1) Tests\Feature\AuthTest::testAuthLogin PDOException: There is already an active transaction
[root]/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:137 [root]/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:113 [root]/vendor/laravel/framework/src/Illuminate/Foundation/Testing/DatabaseTransactions.php:21 [root]/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:129 [root]/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:90
2) Tests\Feature\AuthTest::testAuthGetUser Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'company_id' cannot be null (SQL: insert into
users
(company_id
, [cut]))[root]/vendor/laravel/framework/src/Illuminate/Database/Connection.php:678 [root]/vendor/laravel/framework/src/Illuminate/Database/Connection.php:638 [root]/vendor/laravel/framework/src/Illuminate/Database/Connection.php:472 [root]/vendor/laravel/framework/src/Illuminate/Database/Connection.php:424 [root]/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32 [root]/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2882 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1547 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1052 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1017 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:858 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:275 [root]/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:234 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:278 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:236 [root]/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:230 [root]/tests/Feature/AuthTest.php:73
FAILURES! Tests: 2, Assertions: 0, Errors: 2.
tests/CreatesApplication.php
tests/TestCase.php
migrations/*.php
phpunit.xml
Example test
Any help would be greatly appreciated!