-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Fixed an issue where stache indexing can cause an infinite loop…
… for workers (#11185) Co-authored-by: Simon Geoghegan <[email protected]> Co-authored-by: Jason Varga <[email protected]>
- Loading branch information
1 parent
a345e00
commit 9962a63
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Tests\Stache; | ||
|
||
use Facades\Tests\Factories\EntryFactory; | ||
use Illuminate\Support\Facades\Request; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Entries\Collection; | ||
use Statamic\Statamic; | ||
use Tests\PreventSavingStacheItemsToDisk; | ||
use Tests\TestCase; | ||
|
||
class WorkerInfiniteLoopTest extends TestCase | ||
{ | ||
use PreventSavingStacheItemsToDisk; | ||
|
||
#[Test] | ||
public function infinite_loops_are_prevented_when_running_workers() | ||
{ | ||
// NOTE: We are not using the `config(['cache.default' => 'file'])` override as that | ||
// will cause an infinite loop on failure instead of a segfault. | ||
|
||
// `Statamic::isWorker()` should return false by default. | ||
$this->assertFalse(Statamic::isWorker()); | ||
|
||
// Swap the request with one that will cause `Statamic::isWorker()` to return `true`. | ||
// NOTE: Cannot use `Tests\Fakes\FakeArtisanRequest` as that does not have the cookies | ||
// object initialised and `auth()->user()` will throw an Exception. | ||
Request::swap(request()->duplicate(server: [ | ||
'argv' => ['artisan', 'queue:work'], | ||
'argc' => 2, | ||
])); | ||
|
||
// `Statamic::isWorker()` should return true when being called from any command beginning with `queue:`. | ||
$this->assertTrue(Statamic::isWorker()); | ||
|
||
Collection::make('test')->save(); | ||
EntryFactory::id('alfa-id')->collection('test')->slug('alfa')->data(['title' => 'Alfa'])->create(); | ||
} | ||
} |