mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 14:23:34 +02:00
fix: key Tia worker partials per process to survive batch recycling (#1782)
* fix: key Tia worker partials per process to survive batch recycling * test(tia): refresh visual snapshots for the worker token test --------- Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fc17365bd1
commit
46df02dc28
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Pest\Plugins\Tia;
|
||||
|
||||
function tiaWorkerToken(): string
|
||||
{
|
||||
$tia = new ReflectionClass(Tia::class)->newInstanceWithoutConstructor();
|
||||
|
||||
return new ReflectionMethod($tia, 'workerToken')->invoke($tia);
|
||||
}
|
||||
|
||||
beforeEach(function (): void {
|
||||
unset(
|
||||
$_SERVER['TEST_TOKEN'],
|
||||
$_ENV['TEST_TOKEN'],
|
||||
$_SERVER['UNIQUE_TEST_TOKEN'],
|
||||
$_ENV['UNIQUE_TEST_TOKEN'],
|
||||
);
|
||||
});
|
||||
|
||||
test('prefers the per-process UNIQUE_TEST_TOKEN over the per-slot TEST_TOKEN, so two workers recycled into the same slot get different tokens', function (): void {
|
||||
$_SERVER['TEST_TOKEN'] = '2';
|
||||
|
||||
$_SERVER['UNIQUE_TEST_TOKEN'] = '2_6a690d236824c';
|
||||
$processA = tiaWorkerToken();
|
||||
|
||||
$_SERVER['UNIQUE_TEST_TOKEN'] = '2_9f31be04117a';
|
||||
$processB = tiaWorkerToken();
|
||||
|
||||
expect($processA)->toBe('2_6a690d236824c')
|
||||
->and($processB)->toBe('2_9f31be04117a')
|
||||
->and($processA)->not->toBe($processB);
|
||||
});
|
||||
|
||||
test('falls back to TEST_TOKEN when UNIQUE_TEST_TOKEN is absent', function (): void {
|
||||
$_SERVER['TEST_TOKEN'] = '3';
|
||||
|
||||
expect(tiaWorkerToken())->toBe('3');
|
||||
});
|
||||
Reference in New Issue
Block a user