mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
fix: --retry with parallel
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ coverage.xml
|
|||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
.vscode/
|
.vscode/
|
||||||
|
./temp/
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -12,7 +12,7 @@ use Symfony\Component\Console\Exception\ExceptionInterface;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class InvalidConsoleArgument extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
final class InvalidOption extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a new Exception instance.
|
* Creates a new Exception instance.
|
||||||
@ -27,11 +27,15 @@ final class Cache implements HandlesArguments
|
|||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
|
if (! $this->hasArgument('--parallel', $arguments)) {
|
||||||
$arguments = $this->pushArgument(
|
$arguments = $this->pushArgument(
|
||||||
sprintf('--cache-directory=%s', realpath(self::TEMPORARY_FOLDER)),
|
sprintf('--cache-directory=%s', realpath(self::TEMPORARY_FOLDER)),
|
||||||
$arguments
|
$arguments
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->pushArgument('--cache-result', $arguments);
|
$arguments = $this->pushArgument('--cache-result', $arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
if ($original === sprintf('--%s', $option)) {
|
if ($original === sprintf('--%s', $option)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::startsWith($original, sprintf('--%s=', $option))) {
|
if (Str::startsWith($original, sprintf('--%s=', $option))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,25 @@ final class Parallel implements HandlesArguments
|
|||||||
Parallel\Handlers\Laravel::class,
|
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');
|
$argvValue = Arr::get($_SERVER, 'PARATEST');
|
||||||
|
|
||||||
@ -45,7 +63,7 @@ final class Parallel implements HandlesArguments
|
|||||||
exit($this->runTestSuiteInParallel($arguments));
|
exit($this->runTestSuiteInParallel($arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::isInParallelProcess()) {
|
if (self::isWorker()) {
|
||||||
return $this->runWorkersHandlers($arguments);
|
return $this->runWorkersHandlers($arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,32 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Plugins\Parallel\Handlers;
|
namespace Pest\Plugins\Parallel\Handlers;
|
||||||
|
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
|
||||||
use Pest\Plugins\Concerns\HandleArguments;
|
use Pest\Plugins\Concerns\HandleArguments;
|
||||||
use Pest\Plugins\Parallel\Contracts\HandlersWorkerArguments;
|
use Pest\Plugins\Parallel\Contracts\HandlersWorkerArguments;
|
||||||
use Pest\Plugins\Retry;
|
|
||||||
|
|
||||||
final class Pest implements HandlesArguments, HandlersWorkerArguments
|
final class Pest implements HandlersWorkerArguments
|
||||||
{
|
{
|
||||||
use HandleArguments;
|
use HandleArguments;
|
||||||
|
|
||||||
public function handleArguments(array $arguments): array
|
|
||||||
{
|
|
||||||
if (Retry::$retrying) {
|
|
||||||
$_ENV['PEST_RETRY'] = '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleWorkerArguments(array $arguments): array
|
public function handleWorkerArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
$_SERVER['PEST_PARALLEL'] = '1';
|
$_SERVER['PEST_PARALLEL'] = '1';
|
||||||
|
|
||||||
if (isset($_SERVER['PEST_RETRY'])) {
|
|
||||||
Retry::$retrying = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Plugins;
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
use Pest\Exceptions\InvalidOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -19,10 +20,15 @@ final class Retry implements HandlesArguments
|
|||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if ($this->hasArgument('--retry', $arguments)) {
|
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->popArgument('--retry', $arguments);
|
||||||
|
|
||||||
$arguments = $this->pushArgument('--order-by=defects', $arguments);
|
$arguments = $this->pushArgument('--order-by=defects', $arguments);
|
||||||
$arguments = $this->pushArgument(' --stop-on-defect', $arguments);
|
|
||||||
|
$arguments = $this->pushArgument('--stop-on-failure', $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|||||||
@ -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']
|
||||||
|
|
||||||
|
[90mTests:[39m [31;1m2 failed[39;22m[90m,[39m[39m [39m[33;1m1 risky[39;22m[90m,[39m[39m [39m[36;1m2 todos[39;22m[90m,[39m[39m [39m[33;1m1 skipped[39;22m[90m (2 assertions)[39m
|
||||||
|
[90mDuration:[39m [39m1.00s[39m
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use Pest\Support\Str;
|
|||||||
// HACK: we have to determine our $_SERVER['globalHook-]>calls baseline. This is because
|
// 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.
|
// two other tests are executed before this one due to filename ordering.
|
||||||
$args = $_SERVER['argv'] ?? [];
|
$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;
|
$offset = $single ? 0 : 2;
|
||||||
|
|
||||||
uses()->beforeAll(function () use ($offset) {
|
uses()->beforeAll(function () use ($offset) {
|
||||||
|
|||||||
@ -9,6 +9,6 @@ it('orders by defects and stop on defects if when --retry is used ', function ()
|
|||||||
|
|
||||||
expect($arguments)->toBe([
|
expect($arguments)->toBe([
|
||||||
'--order-by=defects',
|
'--order-by=defects',
|
||||||
' --stop-on-defect',
|
'--stop-on-failure',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user