Replies: 3 comments 7 replies
-
Meanwhile I debugged some details. My
But it seems to me the paratest not use this function for detecting database connection's name. So I try to make a workaround to set the right tenant database name in the $tenant_db_name = $tenantConfig->getDbName() . '_test_' . $token;
DB::statement("CREATE DATABASE IF NOT EXISTS $tenant_db_name");
Config::set('database.connections.test_tenant.database', $tenant_db_name); Later I run into a wierd behaviour of multitenancy package (maybe just for me wierd). When I call // save tenant database name
$preset_tenant_db_name = Config::get('database.connections.test_tenant.database');
// set the first domain as current tenant
Domain::first()->makeCurrent();
// reset tenant database name
Config::set('database.connections.test_tenant.database', $preset_tenant_db_name); And then I ran out from ideas at this point: Artisan::call('tenants:artisan "migrate --database=test_tenant"'); At this point the multitenancy package (I guess) not use the loaded config, but reset again from I would be happy with any idea... Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi @netdjw. Have you solved the above? If so, any chance you could share the solution? |
Beta Was this translation helpful? Give feedback.
-
@netdjw @salvisb Any update on this ? Testing takes lot of timeee. |
Beta Was this translation helpful? Give feedback.
-
So, this
spatie/laravel-multitenancy
package (v3.0.2) is configured like this:config/multitenancy.php
config/database.php:
I've created a
tests/MultitenancyTestCase.php
file for extend the Laravel's baseTestCase
class:Now I run the command:
And I see in the MySQL these databases:
And it sounds goog, but I don't see any
test_tenant_test_1
or similar databases where the parallel testing create databases for tenants. And I see this error in console:Additional info: if I run tests without
--parallel
option, it works fine. The reason why I need to use parallel testing is the number of tests. We have 2600+ test cases and the run time is over 25 minutes with single thread. With parallel option the run time is under 10 minutes. So it's crutial bot in developer experience, both in CI/CD pipeline cost.The question is:
How should I configure tests to create tenant databases for parallel testing?
Beta Was this translation helpful? Give feedback.
All reactions