fix(tests): redis cache store -> array driver in test env (kill quirk 72)

SupplierPortalClient::loadSession, RefreshSupplierSessionJob, CsvReconcileJob and RouteSupplierLeadJob hardcode Cache::store('redis'), bypassing phpunit.xml's CACHE_STORE=array. Under pest --parallel every worker shares the same Memurai instance and the global supplier:session key, so one worker's afterEach forget()/flush() races another worker's mid-test loadSession() -- deterministic 1-2 failures in the tests/Feature/Supplier/ subdir-only run (quirk 72).

TestCase::setUp() repoints the redis cache store at the in-process array driver: each parallel worker gets a hermetic, worker-local cache. Production keeps the real redis driver -- the override only runs under APP_ENV=testing. New RedisCacheStoreIsolationTest guards the invariant.

Verified: tests/Feature/Supplier/ --parallel 6/6 runs 43/43 (was 42/43 +1 error); tests/Unit/Supplier/ 3/3 runs 38/38; full pest --parallel 794/791/3sk/0; Pint + Larastan clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-05-16 09:57:32 +03:00
parent 6e1d437f21
commit 0fa1a7394b
2 changed files with 40 additions and 1 deletions
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Illuminate\Cache\ArrayStore;
use Illuminate\Support\Facades\Cache;
/**
* Quirk 72 regression guard see tests/TestCase.php::setUp().
*
* Supplier code (SupplierPortalClient::loadSession, RefreshSupplierSessionJob,
* CsvReconcileJob, RouteSupplierLeadJob) hardcodes Cache::store('redis'),
* bypassing phpunit.xml's CACHE_STORE=array. The Redis store is a shared
* external service: under `pest --parallel` every worker collides on the
* global `supplier:session` key, so one worker's afterEach forget()/flush()
* races another worker's mid-test loadSession().
*
* TestCase::setUp() repoints the `redis` cache store at the in-process
* `array` driver, making it hermetic and worker-local. This test fails
* (RedisStore) if that override is ever removed.
*/
test('redis cache store resolves to the in-process array driver under tests', function (): void {
expect(Cache::store('redis')->getStore())->toBeInstanceOf(ArrayStore::class);
});
+16 -1
View File
@@ -6,5 +6,20 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
protected function setUp(): void
{
parent::setUp();
// Quirk 72: supplier code (SupplierPortalClient::loadSession,
// RefreshSupplierSessionJob, CsvReconcileJob, RouteSupplierLeadJob)
// hardcodes Cache::store('redis'), bypassing phpunit.xml's
// CACHE_STORE=array. The Redis store is a shared external service —
// under `pest --parallel` every worker collides on the global
// `supplier:session` key, so one worker's afterEach forget()/flush()
// races another worker's mid-test loadSession(). Repoint the `redis`
// cache store at the in-process `array` driver: each worker then gets
// a hermetic, worker-local cache. Production keeps the real `redis`
// driver — this override only ever runs under APP_ENV=testing.
config(['cache.stores.redis.driver' => 'array']);
}
}