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
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:
the DatabaseTransactions trait is needed, the others are "replaced" in whole or in part by ParallelTesting
the new ParallelTesting::setUpTestDatabase() is exactly what I need to seed the databases at creation
no test db definition required as ParallelTesting will already create copies of the form name_test_1, name_test_2
without --recreate-databases, seeding won't be called again as it is only called after its test db is created
My seeds are a bunch of factories, DB::unprepared.
Running art migrate:fresh and art db:seed manually then art test without --parallel, tests work fine. However when running with --parallel --recreate-databases, the seeding does not work and I stumble upon this error:
PDOException: There is already an active transaction
EE 2 / 2 (100%)
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.
Providers/AppServiceProvider.php
<?phpnamespaceApp\Providers;
useIlluminate\Support\Facades\Artisan;
useIlluminate\Support\Facades\ParallelTesting;
useIlluminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/** * Bootstrap any application services. * * @return void */publicfunctionboot()
{
// Executed when a test database is created...
ParallelTesting::setUpTestDatabase(function () {
Artisan::call('db:seed');
});
}
}
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.
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.
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:Providers/AppServiceProvider.php
tests/CreatesApplication.php
tests/TestCase.php
migrations/*.php
phpunit.xml
Example test
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: