From d5d2c2475e5ccea010c8c9752f069b771ab099c6 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 22 Jun 2023 10:28:47 +0200 Subject: [PATCH] Test that the context is central after jobs get processed --- tests/QueueTest.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/QueueTest.php b/tests/QueueTest.php index f88b3934..fca2e04f 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -86,7 +86,7 @@ test('tenant id is not passed to central queues', function () { }); }); -test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) { +test('tenancy is initialized inside queues', function () { withTenantDatabases(); withFailedJobs(); @@ -104,12 +104,11 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) { expect(pest()->valuestore->has('tenant_id'))->toBeFalse(); - if ($shouldEndTenancy) { - tenancy()->end(); - } - pest()->artisan('queue:work --once'); + // Tenancy should not be initialized after the jobs get processed + expect(tenancy()->initialized)->toBeFalse(); + expect(DB::connection('central')->table('failed_jobs')->count())->toBe(0); expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->id); @@ -117,9 +116,9 @@ test('tenancy is initialized inside queues', function (bool $shouldEndTenancy) { $tenant->run(function () use ($user) { expect($user->fresh()->name)->toBe('Bar'); }); -})->with([true, false]);; +}); -test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenancy) { +test('tenancy is initialized when retrying jobs', function () { withFailedJobs(); withTenantDatabases(); @@ -138,18 +137,18 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan expect(pest()->valuestore->has('tenant_id'))->toBeFalse(); - if ($shouldEndTenancy) { - tenancy()->end(); - } - pest()->artisan('queue:work --once'); + expect(tenancy()->initialized)->toBeFalse(); + expect(DB::connection('central')->table('failed_jobs')->count())->toBe(1); expect(pest()->valuestore->get('tenant_id'))->toBeNull(); // job failed pest()->artisan('queue:retry all'); pest()->artisan('queue:work --once'); + expect(tenancy()->initialized)->toBeFalse(); + 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 @@ -157,7 +156,7 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan $tenant->run(function () use ($user) { expect($user->fresh()->name)->toBe('Bar'); }); -})->with([true, false]); +}); test('the tenant used by the job doesnt change when the current tenant changes', function () { withTenantDatabases();