From 0fa1a7394b643d527553bd63e30c71687ae860e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Sat, 16 May 2026 09:57:32 +0300 Subject: [PATCH] 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) --- .../Feature/RedisCacheStoreIsolationTest.php | 24 +++++++++++++++++++ app/tests/TestCase.php | 17 ++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/tests/Feature/RedisCacheStoreIsolationTest.php diff --git a/app/tests/Feature/RedisCacheStoreIsolationTest.php b/app/tests/Feature/RedisCacheStoreIsolationTest.php new file mode 100644 index 00000000..c80e8e17 --- /dev/null +++ b/app/tests/Feature/RedisCacheStoreIsolationTest.php @@ -0,0 +1,24 @@ +getStore())->toBeInstanceOf(ArrayStore::class); +}); diff --git a/app/tests/TestCase.php b/app/tests/TestCase.php index fe1ffc2f..e5f98cf4 100644 --- a/app/tests/TestCase.php +++ b/app/tests/TestCase.php @@ -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']); + } }