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

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ coverage.xml
*.swp
*.swo
.vscode/
./temp/

File diff suppressed because one or more lines are too long

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;

View File

@ -0,0 +1,24 @@
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:105|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' type='comparisonFailure' actual='true' expected='false' flowId='1234']
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
##teamcity[testFinished name='it can be ignored because of no assertions' duration='100000' flowId='1234']
##teamcity[testStarted name='it can be ignored because it is skipped' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because it is skipped' flowId='1234']
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:105|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' flowId='1234']
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']
##teamcity[testFinished name='it is not done yet' duration='100000' flowId='1234']
##teamcity[testStarted name='build this one.' locationHint='pest_qn://tests/.tests/Failure.php::build this one.' flowId='1234']
##teamcity[testIgnored name='build this one.' message='This test was ignored.' details='' flowId='1234']
##teamcity[testFinished name='build this one.' duration='100000' flowId='1234']
##teamcity[testSuiteFinished name='Tests/tests/Failure' flowId='1234']
Tests: 2 failed, 1 risky, 2 todos, 1 skipped (2 assertions)
Duration: 1.00s

View File

@ -6,7 +6,7 @@ use Pest\Support\Str;
// HACK: we have to determine our $_SERVER['globalHook-]>calls baseline. This is because
// two other tests are executed before this one due to filename ordering.
$args = $_SERVER['argv'] ?? [];
$single = (isset($args[1]) && Str::endsWith(__FILE__, $args[1])) || Parallel::isInParallelProcess();
$single = (isset($args[1]) && Str::endsWith(__FILE__, $args[1])) || Parallel::isWorker();
$offset = $single ? 0 : 2;
uses()->beforeAll(function () use ($offset) {

View File

@ -9,6 +9,6 @@ it('orders by defects and stop on defects if when --retry is used ', function ()
expect($arguments)->toBe([
'--order-by=defects',
' --stop-on-defect',
'--stop-on-failure',
]);
});