mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 06:13:35 +02:00
Prevent memory exhaustion when generating TIA graphs with PCOV (#1875)
* fix(tia): preserve memory limit during pcov restart * chore: update test expectations * fix: stabilize tia replay test in ci
This commit is contained in:
@@ -52,13 +52,8 @@ final class PcovRestarter implements Restarter
|
|||||||
$env = $this->inheritEnv();
|
$env = $this->inheritEnv();
|
||||||
$env[self::ENV_RESTARTED] = '1';
|
$env[self::ENV_RESTARTED] = '1';
|
||||||
|
|
||||||
$command = array_merge(
|
|
||||||
[PHP_BINARY, '-d', 'pcov.directory='.$projectRoot],
|
|
||||||
array_values($arguments),
|
|
||||||
);
|
|
||||||
|
|
||||||
$proc = @proc_open(
|
$proc = @proc_open(
|
||||||
$command,
|
$this->command($projectRoot, $arguments),
|
||||||
[STDIN, STDOUT, STDERR],
|
[STDIN, STDOUT, STDERR],
|
||||||
$pipes,
|
$pipes,
|
||||||
null,
|
null,
|
||||||
@@ -74,6 +69,24 @@ final class PcovRestarter implements Restarter
|
|||||||
exit($exitCode === -1 ? 1 : $exitCode);
|
exit($exitCode === -1 ? 1 : $exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, string> $arguments
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function command(string $projectRoot, array $arguments): array
|
||||||
|
{
|
||||||
|
return array_merge(
|
||||||
|
[
|
||||||
|
PHP_BINARY,
|
||||||
|
'-d',
|
||||||
|
'memory_limit='.ini_get('memory_limit'),
|
||||||
|
'-d',
|
||||||
|
'pcov.directory='.$projectRoot,
|
||||||
|
],
|
||||||
|
array_values($arguments),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2051,6 +2051,9 @@
|
|||||||
✓ preset invalid name
|
✓ preset invalid name
|
||||||
✓ preset → myFramework
|
✓ preset → myFramework
|
||||||
|
|
||||||
|
PASS Tests\Unit\Restarters\PcovRestarter
|
||||||
|
✓ it preserves the active memory limit in the restarted process
|
||||||
|
|
||||||
PASS Tests\Unit\Support\Arr
|
PASS Tests\Unit\Support\Arr
|
||||||
✓ last → it should return false for an empty arary
|
✓ last → it should return false for an empty arary
|
||||||
✓ last → it should return the last element for an array with a single element
|
✓ last → it should return the last element for an array with a single element
|
||||||
@@ -2234,4 +2237,4 @@
|
|||||||
✓ pass with dataset with ('my-datas-set-value')
|
✓ pass with dataset with ('my-datas-set-value')
|
||||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1581 passed (3434 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1582 passed (3435 assertions)
|
||||||
@@ -56,6 +56,7 @@ it('does not run user hooks when replaying cached skipped and incomplete results
|
|||||||
'PARATEST' => 0,
|
'PARATEST' => 0,
|
||||||
'PAO_DISABLE' => '1',
|
'PAO_DISABLE' => '1',
|
||||||
'HOME' => $home,
|
'HOME' => $home,
|
||||||
|
'CI_DEFAULT_BRANCH' => $branch,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Pest\Restarters\PcovRestarter;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
it('preserves the active memory limit in the restarted process', function (): void {
|
||||||
|
$originalMemoryLimit = ini_get('memory_limit');
|
||||||
|
|
||||||
|
try {
|
||||||
|
ini_set('memory_limit', '1234M');
|
||||||
|
|
||||||
|
$command = new ReflectionMethod(PcovRestarter::class, 'command')
|
||||||
|
->invoke(new PcovRestarter, __DIR__, ['-r', 'fwrite(STDOUT, (string) ini_get("memory_limit"));']);
|
||||||
|
|
||||||
|
assert(is_array($command));
|
||||||
|
|
||||||
|
$process = new Process($command);
|
||||||
|
$process->mustRun();
|
||||||
|
|
||||||
|
expect($process->getOutput())->toBe('1234M');
|
||||||
|
} finally {
|
||||||
|
ini_set('memory_limit', (string) $originalMemoryLimit);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -26,13 +26,13 @@ test('parallel', function () use ($run): void {
|
|||||||
$file = file_get_contents(__FILE__);
|
$file = file_get_contents(__FILE__);
|
||||||
$file = preg_replace(
|
$file = preg_replace(
|
||||||
'/\$expected = \'.*?\';/',
|
'/\$expected = \'.*?\';/',
|
||||||
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1563 passed (3379 assertions)';",
|
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1564 passed (3380 assertions)';",
|
||||||
$file,
|
$file,
|
||||||
);
|
);
|
||||||
file_put_contents(__FILE__, $file);
|
file_put_contents(__FILE__, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1563 passed (3379 assertions)';
|
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1564 passed (3380 assertions)';
|
||||||
|
|
||||||
expect($output)
|
expect($output)
|
||||||
->toContain("Tests: {$expected}")
|
->toContain("Tests: {$expected}")
|
||||||
|
|||||||
Reference in New Issue
Block a user