@@ -9,6 +9,9 @@ use Laravel\Fortify\Features;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
/** @var array<string, resource> Locks held until this test process exits. */
|
||||
private static array $qaDatabaseLocks = [];
|
||||
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = parent::createApplication();
|
||||
@@ -28,6 +31,20 @@ abstract class TestCase extends BaseTestCase
|
||||
|| ! in_array($url, [null, ''], true)) {
|
||||
throw new \LogicException('PHPUnit PostgreSQL target rejected: configure an explicit loopback *_test database with no DB_URL.');
|
||||
}
|
||||
|
||||
// Two test processes must not migrate/clean the same isolated database concurrently.
|
||||
$lockKey = hash('sha256', $host.':'.($connection['port'] ?? '').':'.$database);
|
||||
if (! isset(self::$qaDatabaseLocks[$lockKey])) {
|
||||
$handle = fopen($app->storagePath('framework/qa-database-'.$lockKey.'.lock'), 'c');
|
||||
if ($handle === false) {
|
||||
throw new \LogicException('QA database execution lock unavailable.');
|
||||
}
|
||||
if (! flock($handle, LOCK_EX | LOCK_NB)) {
|
||||
fclose($handle);
|
||||
throw new \LogicException('Another test process owns this QA database; run suites sequentially or use separate *_test databases.');
|
||||
}
|
||||
self::$qaDatabaseLocks[$lockKey] = $handle;
|
||||
}
|
||||
}
|
||||
|
||||
// migrate:fresh only clears the connection's public search path. This module owns a separate schema.
|
||||
|
||||
Reference in New Issue
Block a user