Skip to content

Commit 8fabbbd

Browse files
committed
support PersistentQueueTenancyBootstrapper
1 parent 6a047d3 commit 8fabbbd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

setup/alternative/_alternative_setup.sh

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ cp ../setup/alternative/database.php config/database.php
1212

1313
rm app/Providers/AppServiceProvider.php
1414
cp ../setup/alternative/AppServiceProvider.php app/Providers/AppServiceProvider.php
15+
16+
if [ -f vendor/stancl/tenancy/src/Bootstrappers/PersistentQueueTenancyBootstrapper.php ]; then
17+
sed -i 's/QueueTenancyBootstrapper/PersistentQueueTenancyBootstrapper/g' config/tenancy.php
18+
fi

test.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ expect_worker_context() {
9090
rm -f src/database.sqlite
9191
rm -f src/database/tenantfoo.sqlite
9292
rm -f src/database/tenantbar.sqlite
93+
rm -f src/abc
94+
rm -f src/sync_context
9395

9496
docker compose up -d redis # in case it's not running - the below setup code needs Redis to be running
9597

@@ -231,6 +233,9 @@ echo
231233
echo "-------- SYNC PHASE --------"
232234
echo
233235

236+
# The only thing we can check here is that dispatching a job doesn't revert the context to central
237+
# when executed synchronously.
238+
234239
docker compose run --rm queue php artisan tinker -v --execute "tenancy()->initialize('foo'); App\Jobs\FooJob::dispatchSync(); file_put_contents('sync_context', tenant() ? ('tenant_' . tenant('id')) : 'central');"
235240
without_queue_assertions assert_tenant_users foo 5
236241
without_queue_assertions assert_tenant_users bar 1
@@ -256,10 +261,12 @@ assert_tenant_users bar 2
256261
assert_central_users 2
257262
echo "OK: User created in tenant bar"
258263

259-
docker compose exec -T queue php artisan tinker --execute "\$tenant = App\Models\Tenant::find('bar'); \$tenant->update(['abc' => 'def']); \$tenant->run(function () { dispatch(new App\Jobs\LogAbcJob); });"
264+
EXPECTED_ABC=$(openssl rand -base64 12)
265+
266+
docker compose exec -T queue php artisan tinker --execute "\$tenant = App\Models\Tenant::find('bar'); \$tenant->update(['abc' => '${EXPECTED_ABC}']); \$tenant->run(function () { dispatch(new App\Jobs\LogAbcJob); });"
260267
sleep 5
261268

262-
if grep -q 'def' src/abc; then
269+
if grep -q $EXPECTED_ABC src/abc; then
263270
echo "OK: Worker notices changes made to the current tenant outside the worker"
264271
else
265272
if [ "$FORCEREFRESH" -eq 1 ]; then

0 commit comments

Comments
 (0)