fix: --retry with parallel

This commit is contained in:
Nuno Maduro
2023-02-11 17:39:46 +00:00
parent 6ddc5c8572
commit 052b9e051b
11 changed files with 67 additions and 28 deletions

View File

@ -12,7 +12,7 @@ use Symfony\Component\Console\Exception\ExceptionInterface;
/**
* @internal
*/
final class InvalidConsoleArgument extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
final class InvalidOption extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
{
/**
* Creates a new Exception instance.

View File

@ -27,11 +27,15 @@ final class Cache implements HandlesArguments
*/
public function handleArguments(array $arguments): array
{
$arguments = $this->pushArgument(
sprintf('--cache-directory=%s', realpath(self::TEMPORARY_FOLDER)),
$arguments
);
if (! $this->hasArgument('--parallel', $arguments)) {
$arguments = $this->pushArgument(
sprintf('--cache-directory=%s', realpath(self::TEMPORARY_FOLDER)),
$arguments
);
return $this->pushArgument('--cache-result', $arguments);
$arguments = $this->pushArgument('--cache-result', $arguments);
}
return $arguments;
}
}

View File

@ -55,6 +55,7 @@ final class Coverage implements AddsOutput, HandlesArguments
if ($original === sprintf('--%s', $option)) {
return true;
}
if (Str::startsWith($original, sprintf('--%s=', $option))) {
return true;
}

View File

@ -30,7 +30,25 @@ final class Parallel implements HandlesArguments
Parallel\Handlers\Laravel::class,
];
public static function isInParallelProcess(): bool
/**
* If the
*/
public static function isCommand(): bool
{
// get binary name
Arr::get($_SERVER, 'argv.0');
$argvValue = Arr::get($_ENV, 'PARATEST');
assert(is_string($argvValue) || is_int($argvValue) || is_null($argvValue));
return ((int) $argvValue) === 1;
}
/**
* If the
*/
public static function isWorker(): bool
{
$argvValue = Arr::get($_SERVER, 'PARATEST');
@ -45,7 +63,7 @@ final class Parallel implements HandlesArguments
exit($this->runTestSuiteInParallel($arguments));
}
if (self::isInParallelProcess()) {
if (self::isWorker()) {
return $this->runWorkersHandlers($arguments);
}

View File

@ -4,32 +4,17 @@ declare(strict_types=1);
namespace Pest\Plugins\Parallel\Handlers;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugins\Concerns\HandleArguments;
use Pest\Plugins\Parallel\Contracts\HandlersWorkerArguments;
use Pest\Plugins\Retry;
final class Pest implements HandlesArguments, HandlersWorkerArguments
final class Pest implements HandlersWorkerArguments
{
use HandleArguments;
public function handleArguments(array $arguments): array
{
if (Retry::$retrying) {
$_ENV['PEST_RETRY'] = '1';
}
return $arguments;
}
public function handleWorkerArguments(array $arguments): array
{
$_SERVER['PEST_PARALLEL'] = '1';
if (isset($_SERVER['PEST_RETRY'])) {
Retry::$retrying = true;
}
return $arguments;
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Pest\Plugins;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Exceptions\InvalidOption;
/**
* @internal
@ -19,10 +20,15 @@ final class Retry implements HandlesArguments
public function handleArguments(array $arguments): array
{
if ($this->hasArgument('--retry', $arguments)) {
if ($this->hasArgument('--parallel', $arguments)) {
throw new InvalidOption('The --retry option is not supported when running in parallel.');
}
$arguments = $this->popArgument('--retry', $arguments);
$arguments = $this->pushArgument('--order-by=defects', $arguments);
$arguments = $this->pushArgument(' --stop-on-defect', $arguments);
$arguments = $this->pushArgument('--stop-on-failure', $arguments);
}
return $arguments;