1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

Merge remote-tracking branch 'origin/master' into merge-public-repo-master

This commit is contained in:
Samuel Štancl 2024-02-10 21:55:54 +01:00
commit a430b1de29
2 changed files with 31 additions and 6 deletions

View file

@ -111,6 +111,8 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) {
pest()->artisan('queue:work --once');
expect(! tenancy()->initialized)->toBe($shouldEndTenancy);
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0);
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id);
@ -168,12 +170,21 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan
pest()->artisan('queue:work --once');
expect(! tenancy()->initialized)->toBe($shouldEndTenancy);
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(1);
expect(pest()->valuestore->get('tenant_id'))->toBeNull(); // job failed
pest()->artisan('queue:retry all');
if ($shouldEndTenancy) {
tenancy()->end();
}
pest()->artisan('queue:work --once');
expect(! tenancy()->initialized)->toBe($shouldEndTenancy);
expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0);
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id); // job succeeded
@ -202,6 +213,22 @@ test('the tenant used by the job doesnt change when the current tenant changes',
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant1->getTenantKey());
});
test('tenant connections do not persist after tenant jobs get processed', function() {
withTenantDatabases();
$tenant = Tenant::create();
tenancy()->initialize($tenant);
dispatch(new TestJob(pest()->valuestore));
tenancy()->end();
pest()->artisan('queue:work --once');
expect(collect(DB::select('SHOW FULL PROCESSLIST'))->pluck('db'))->not()->toContain($tenant->database()->getName());
});
function createValueStore(): void
{
$valueStorePath = __DIR__ . '/Etc/tmp/queuetest.json';