fix: resolve parallel test execution failures (Issue #62) #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Issue #62 reported intermittent test failures (~1-10% failure rate) when running tests with
php artisan test --parallel. The error was:Root Cause
All tests shared the same KEK (Key Encryption Key) file at
storage/app/keys/kek.key. When multiple test processes ran in parallel:Solution
Implemented Option 1 from Issue #62 (Per-Process KEK Files) by making the KEK file path configurable:
Changes
app/Models/TenantKey.php:protected static ?string $kekPath = nullpropertygetKekPath()to check the static property before returning default pathpublic static function setKekPath(?string $path): voidto allow tests to set custom KEK pathstests/Feature/TenantKeyTest.php:getProcessKekPath()helper returningstorage/app/keys/kek-test-{pid}.keybeforeEach()to set process-specific KEK pathafterEach()to cleanup KEK file and reset pathtests/Feature/PersonTest.php:getPersonTestKekPath()helper returningstorage/app/keys/kek-test-{pid}.keybeforeEach()to set process-specific KEK pathafterEach()to cleanup KEK file and reset pathEach test process now uses its own unique KEK file identified by process ID, completely eliminating race conditions.
Testing
Validated the fix with 10 consecutive parallel test runs:
Results:
Acceptance Criteria from Issue #62
php artisan test --parallelFixes #62