storagePath(); $temporary = $originalStorage.'/framework/testing/process-recovery-'.Str::uuid(); File::ensureDirectoryExists($temporary.'/framework'); app()->useStoragePath($temporary); $path = storage_path('framework/replenishment-command.lock'); $worker = new Process([PHP_BINARY, '-r', '$h = fopen($argv[1], "c"); if (!$h || !flock($h, LOCK_EX | LOCK_NB)) { exit(2); } echo "LOCKED"; fflush(STDOUT); sleep(30);', $path], timeout: 10); $contender = new ReplenishmentProcessLock; try { $worker->start(); expect($worker->waitUntil(fn ($type, $output) => str_contains($output, 'LOCKED')))->toBeTrue(); expect($contender->acquire())->toBeFalse(); $worker->stop(0); expect($worker->isRunning())->toBeFalse(); expect(File::exists($path))->toBeTrue(); expect($contender->acquire())->toBeTrue(); } finally { $worker->stop(0); $contender->release(); app()->useStoragePath($originalStorage); File::deleteDirectory($temporary); } });