mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +00:00
fix #1277: consume PendingDispatch return values in Tenancy::run()
This commit is contained in:
parent
99357d94df
commit
3c183e45d9
2 changed files with 21 additions and 3 deletions
|
|
@ -80,6 +80,10 @@ class Tenancy
|
|||
$this->initialize($tenant);
|
||||
$result = $callback($tenant);
|
||||
|
||||
if ($result instanceof \Illuminate\Foundation\Bus\PendingDispatch) { // #1277
|
||||
$result = null;
|
||||
}
|
||||
|
||||
if ($originalTenant) {
|
||||
$this->initialize($originalTenant);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,15 +6,12 @@ use Illuminate\Bus\Queueable;
|
|||
use Spatie\Valuestore\Valuestore;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Tests\Etc\User;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Stancl\Tenancy\Events\TenancyEnded;
|
||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
|
|
@ -229,6 +226,23 @@ test('tenant connections do not persist after tenant jobs get processed', functi
|
|||
expect(collect(DB::select('SHOW FULL PROCESSLIST'))->pluck('db'))->not()->toContain($tenant->database()->getName());
|
||||
});
|
||||
|
||||
// Regression test for #1277
|
||||
test('dispatching a job from a tenant run arrow function dispatches it immediately', function () {
|
||||
withTenantDatabases();
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
$result = $tenant->run(fn () => dispatch(new TestJob(pest()->valuestore)));
|
||||
expect($result)->toBe(null);
|
||||
|
||||
expect(tenant())->toBe(null);
|
||||
expect(pest()->valuestore->has('tenant_id'))->toBeFalse();
|
||||
pest()->artisan('queue:work --once');
|
||||
expect(tenant())->toBe(null);
|
||||
|
||||
expect(pest()->valuestore->get('tenant_id'))->toBe('The current tenant id is: ' . $tenant->getTenantKey());
|
||||
});
|
||||
|
||||
function createValueStore(): void
|
||||
{
|
||||
$valueStorePath = __DIR__ . '/Etc/tmp/queuetest.json';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue