mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 16:34:03 +00:00
Test pulling pending tenants concurrently
This commit is contained in:
parent
652bc987ce
commit
0913614d5f
2 changed files with 112 additions and 0 deletions
34
tests/Etc/pull-worker.php
Normal file
34
tests/Etc/pull-worker.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Worker for the "concurrent pulls" tests.
|
||||
* Separate OS process that boots the same test env and calls pullPendingFromPool().
|
||||
* Since multiple processes run at once, they race for the pool.
|
||||
*
|
||||
* Used like `php pull-worker.php <startAtUnixFloat> <firstOrCreate:0|1>`
|
||||
*
|
||||
* Outputs the key of the pulled tenant, or "null" if nothing was pulled.
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
$startAt = (float) ($argv[1] ?? 0);
|
||||
$firstOrCreate = ($argv[2] ?? '0') === '1';
|
||||
|
||||
// createApplication() replays the suite's central-MySQL config without running setUp(),
|
||||
// so the pending tenants the parent test created survive into this process.
|
||||
(new class('pull-worker') extends TestCase {})->createApplication();
|
||||
|
||||
// Wait so that every worker pulls at the same time
|
||||
if ($startAt > 0.0) {
|
||||
time_sleep_until($startAt);
|
||||
}
|
||||
|
||||
$tenant = Tenant::pullPendingFromPool($firstOrCreate);
|
||||
|
||||
fwrite(STDOUT, $tenant?->getKey() ?? 'null');
|
||||
Loading…
Add table
Add a link
Reference in a new issue