fix: honor all stop-on-* flags in parallel mode (#1684)

* fix: honor all stop-on-* flags in parallel mode

Previously --stop-on-failure was the only flag honored in parallel
mode, and it only cleared pending tests when the exit code was
non-zero. The rest (--stop-on-defect, --stop-on-error, --stop-on-risky,
--stop-on-incomplete, --stop-on-warning, --stop-on-notice,
--stop-on-deprecation, --stop-on-skipped) were silently ignored.

WrapperRunner now precomputes the set of progress-file characters that
should trigger a stop (F, E, R, I, W, N, D, S) based on the configured
flags, and scans each worker's progress file for them after every
cycle. Once any matching outcome is seen, the pending queue is cleared.

Up to N-1 in-flight tests (where N is --processes) can still complete
after the first stop-worthy outcome — stopping them mid-run would risk
corrupting shared state.

Closes #1463.

* fix: preserve parallel stop conditions on Pest 5

* test: expand parallel stop-on regression coverage
This commit is contained in:
Aleksandr Štšepelin
2026-11-16 22:19:46 +02:00
committed by GitHub
parent fbaa7fe8e9
commit 9dc8c1d5cb
39 changed files with 735 additions and 11 deletions
+7
View File
@@ -6,8 +6,10 @@ use ParaTest\WrapperRunner\ApplicationForWrapperWorker;
use ParaTest\WrapperRunner\WrapperWorker;
use Pest\Kernel;
use Pest\Plugins\Actions\CallsHandleArguments;
use Pest\Plugins\Parallel\Paratest\StopConditions;
use Pest\Support\Container;
use Pest\TestSuite;
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
@@ -99,6 +101,8 @@ $bootPest = (static function (): void {
(int) ($getopt['testdox-columns'] ?? null),
);
$stopConditions = null;
while (true) {
if (feof(STDIN)) {
$application->end();
@@ -113,6 +117,9 @@ $bootPest = (static function (): void {
$exitCode = $application->runTest(realpath(trim($testPath)));
$stopConditions ??= new StopConditions(ConfigurationRegistry::get());
$stopConditions->write($getopt['test-result-file'].'.stop');
fwrite($statusFile, (string) $exitCode);
fflush($statusFile);
}
+3
View File
@@ -29,6 +29,7 @@ final class Parallel implements HandlesArguments
Parallel\Handlers\Parallel::class,
Parallel\Handlers\Pest::class,
Parallel\Handlers\Laravel::class,
Parallel\Handlers\StopOn::class,
];
/**
@@ -148,6 +149,8 @@ final class Parallel implements HandlesArguments
$command->setName('Pest');
$command->setVersion(version());
Parallel\Handlers\StopOn::configureOptions($command->find('paratest')->getDefinition());
return $command;
}
+76
View File
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins\Parallel\Handlers;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugins\Parallel\Contracts\HandlersWorkerArguments;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
final class StopOn implements HandlersWorkerArguments, HandlesArguments
{
private const array OPTIONS = [
'--stop-on-defect',
'--stop-on-error',
'--stop-on-failure',
'--stop-on-warning',
'--stop-on-risky',
'--stop-on-deprecation',
'--stop-on-notice',
'--stop-on-skipped',
'--stop-on-incomplete',
];
public function handleArguments(array $arguments): array
{
foreach ($arguments as $index => $argument) {
[$option, $value] = array_pad(explode('=', $argument, 2), 2, '');
if (in_array($option, self::OPTIONS, true)
&& in_array($value, ['', '0'], true)) {
$arguments[$index] = $option.'=1';
}
}
return $arguments;
}
public function handleWorkerArguments(array $arguments): array
{
$arguments = array_values($arguments);
foreach ($arguments as $index => $argument) {
if (! in_array($argument, self::OPTIONS, true)
|| ! isset($arguments[$index + 1])
|| str_starts_with($arguments[$index + 1], '--')) {
continue;
}
$arguments[$index] .= '='.$arguments[$index + 1];
unset($arguments[$index + 1]);
}
return array_values($arguments);
}
public static function configureOptions(InputDefinition $definition): void
{
$options = $definition->getOptions();
foreach (self::OPTIONS as $argument) {
$name = substr($argument, 2);
$option = $options[$name];
$options[$name] = new InputOption(
$name,
$option->getShortcut(),
InputOption::VALUE_OPTIONAL,
$option->getDescription(),
false,
);
}
$definition->setOptions($options);
}
}
@@ -0,0 +1,216 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins\Parallel\Paratest;
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollector;
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade;
use PHPUnit\TestRunner\TestResult\Issues\Issue;
use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\Configuration;
use RuntimeException;
final class StopConditions
{
/**
* @var array<string, positive-int>
*/
private readonly array $thresholds;
/**
* @var array<string, array<string, non-negative-int>>
*/
private array $workerCounts = [];
/**
* @var array<string, non-negative-int>
*/
private array $totals = [];
/**
* @var array<string, array<string, true>>
*/
private array $issueIds = [];
public function __construct(private readonly Configuration $configuration)
{
$this->thresholds = array_filter([
'defect' => $configuration->stopOnDefectThreshold(),
'error' => $configuration->stopOnErrorThreshold(),
'failure' => $configuration->stopOnFailureThreshold(),
'warning' => $configuration->stopOnWarningThreshold(),
'risky' => $configuration->stopOnRiskyThreshold(),
'deprecation' => $configuration->stopOnDeprecationThreshold(),
'notice' => $configuration->stopOnNoticeThreshold(),
'incomplete' => $configuration->stopOnIncompleteThreshold(),
'skipped' => $configuration->stopOnSkippedThreshold(),
], static fn (int $threshold): bool => $threshold > 0);
}
public function write(string $filename): void
{
if ($this->thresholds === []) {
return;
}
$result = TestResultFacade::result();
$state = json_encode([
'counts' => $this->counts($result),
'issues' => $this->issues($result),
], JSON_THROW_ON_ERROR);
if (file_put_contents($filename.'.tmp', $state) === false
|| ! rename($filename.'.tmp', $filename)) {
throw new RuntimeException(sprintf('Unable to write the parallel stop counts to [%s].', $filename));
}
}
public function read(string $filename): void
{
if ($this->thresholds === []) {
return;
}
$contents = file_get_contents($filename);
if ($contents === false) {
throw new RuntimeException(sprintf('Unable to read the parallel stop counts from [%s].', $filename));
}
$state = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
if (! is_array($state)
|| ! isset($state['counts'], $state['issues'])
|| ! is_array($state['counts'])
|| ! is_array($state['issues'])) {
throw new RuntimeException(sprintf('Invalid parallel stop counts in [%s].', $filename));
}
$this->addCounts($filename, $state['counts']);
$this->addIssues($filename, $state['issues']);
}
public function shouldStop(): bool
{
return array_any($this->thresholds, function (int $threshold, string $outcome): bool {
$issueType = $outcome === 'defect' ? 'warning' : $outcome;
$count = ($this->totals[$outcome] ?? 0) + count($this->issueIds[$issueType] ?? []);
return $count >= $threshold;
});
}
/**
* @return array<string, int>
*/
private function counts(TestResult $result): array
{
$counts = [
'error' => $result->numberOfTestErroredEvents(),
'failure' => $result->numberOfTestFailedEvents(),
'warning' => $result->numberOfPhpunitWarnings(),
'risky' => $result->numberOfTestsWithTestConsideredRiskyEvents(),
'deprecation' => $this->numberOfDeprecations(),
'notice' => 0,
'incomplete' => $result->numberOfTestMarkedIncompleteEvents(),
'skipped' => $result->numberOfTestSkippedEvents(),
];
$counts['defect'] = $counts['error'] + $counts['failure'] + $counts['warning'] + $counts['risky'];
return $counts;
}
/**
* @return array<'warning'|'notice', list<non-empty-string>>
*/
private function issues(TestResult $result): array
{
$issues = [];
if (isset($this->thresholds['warning']) || isset($this->thresholds['defect'])) {
$issues['warning'] = array_merge(
$this->issueKeys($result->warnings(), 'user'),
$this->issueKeys($result->phpWarnings(), 'php'),
);
}
if (isset($this->thresholds['notice'])) {
$issues['notice'] = array_merge(
$this->issueKeys($result->notices(), 'user'),
$this->issueKeys($result->phpNotices(), 'php'),
);
}
return $issues;
}
/**
* @return non-negative-int
*/
private function numberOfDeprecations(): int
{
$deprecations = DeprecationCollector::filteredDeprecations();
if ($this->configuration->hasSpecificDeprecationToStopOn()) {
$message = $this->configuration->specificDeprecationToStopOn();
$deprecations = array_filter($deprecations, static fn (string $deprecation): bool => str_contains($deprecation, $message));
}
return count($deprecations);
}
/**
* @param array<array-key, mixed> $counts
*/
private function addCounts(string $filename, array $counts): void
{
foreach (array_keys($this->thresholds) as $outcome) {
if (! isset($counts[$outcome]) || ! is_int($counts[$outcome]) || $counts[$outcome] < 0) {
throw new RuntimeException(sprintf('Invalid parallel stop counts in [%s].', $filename));
}
$previous = $this->workerCounts[$filename][$outcome] ?? 0;
$increase = $counts[$outcome] - $previous;
if ($increase < 0) {
throw new RuntimeException(sprintf('Parallel stop counts decreased in [%s].', $filename));
}
$this->totals[$outcome] = ($this->totals[$outcome] ?? 0) + $increase;
$this->workerCounts[$filename][$outcome] = $counts[$outcome];
}
}
/**
* @param array<array-key, mixed> $issues
*/
private function addIssues(string $filename, array $issues): void
{
foreach ($issues as $outcome => $ids) {
if (! in_array($outcome, ['warning', 'notice'], true) || ! is_array($ids)) {
throw new RuntimeException(sprintf('Invalid parallel stop issues in [%s].', $filename));
}
foreach ($ids as $id) {
if (! is_string($id)) {
throw new RuntimeException(sprintf('Invalid parallel stop issue in [%s].', $filename));
}
$this->issueIds[$outcome][$id] = true;
}
}
}
/**
* @param list<Issue> $issues
* @return list<non-empty-string>
*/
private function issueKeys(array $issues, string $origin): array
{
return array_map(
static fn (Issue $issue): string => hash('sha256', implode(':', [$origin, $issue->file(), $issue->line(), $issue->description()])),
$issues,
);
}
}
+16 -10
View File
@@ -78,8 +78,6 @@ final class WrapperRunner implements RunnerInterface
/** @var list<non-empty-list<non-empty-string>> */
private array $pending = [];
private int $exitcode = -1;
/** @var array<positive-int,WrapperWorker> */
private array $workers = [];
@@ -122,6 +120,8 @@ final class WrapperRunner implements RunnerInterface
/** @var non-empty-string[] */
private readonly array $parameters;
private readonly StopConditions $stopConditions;
private CodeCoverageFilterRegistry $codeCoverageFilterRegistry;
/** @var non-empty-string */
@@ -133,6 +133,7 @@ final class WrapperRunner implements RunnerInterface
) {
$this->printer = new ResultPrinter($output, $options);
$this->timer = new Timer;
$this->stopConditions = new StopConditions($options->configuration);
$wrapper = realpath(
dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'worker.php',
@@ -248,17 +249,18 @@ final class WrapperRunner implements RunnerInterface
$this->flushWorker($worker);
if ($this->stopConditions->shouldStop()) {
$this->pending = [];
break;
}
if ($batchSize !== 0 && $this->batches[$token] >= $batchSize) {
$this->destroyWorker($token);
$worker = $this->startWorker($token);
}
if (
$this->exitcode > 0
&& $this->options->configuration->stopOnFailureThreshold() > 0
) {
$this->pending = [];
} elseif (($pending = array_shift($this->pending)) !== null) {
if (($pending = array_shift($this->pending)) !== null) {
$worker->assign($pending);
$this->batches[$token] += count($pending);
}
@@ -275,6 +277,7 @@ final class WrapperRunner implements RunnerInterface
if ($testResultFile !== '') {
$this->requiredTestResultFiles[$testResultFile] = true;
$this->stopConditions->read($testResultFile.'.stop');
}
if (isset($worker->coverageFile) && $worker->coverageFile->getPathname() !== '') {
@@ -282,7 +285,6 @@ final class WrapperRunner implements RunnerInterface
}
}
$this->exitcode = max($this->exitcode, $worker->getExitCode());
$this->printer->printFeedback(
$worker->progressFile,
$worker->unexpectedOutputFile,
@@ -501,7 +503,11 @@ final class WrapperRunner implements RunnerInterface
$this->clearFiles($this->statusFiles);
$this->clearFiles($this->progressFiles);
$this->clearFiles($this->unexpectedOutputFiles);
$this->clearFiles($this->testResultFiles);
foreach ($this->testResultFiles as $file) {
$this->clearFiles([$file, new SplFileInfo($file->getPathname().'.stop')]);
}
$this->clearFiles($this->resultCacheFiles);
$this->clearFiles($this->coverageFiles);
$this->clearFiles($this->junitFiles);
+69 -1
View File
@@ -2419,6 +2419,74 @@
PASS Tests\Visual\ParallelNestedDatasets
✓ parallel loads nested datasets from nested directories
PASS Tests\Visual\ParallelStopOn
✓ parallel stop-on fixtures run completely without a stop flag with dataset "failure"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "error"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "risky"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "incomplete"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "warning"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "notice"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "deprecation"
✓ parallel stop-on fixtures run completely without a stop flag with dataset "skipped"
✓ parallel honors stop-on flags with worker recycling with dataset "failure" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "failure" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "defect" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "defect" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "error" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "error" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "risky" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "risky" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "incomplete" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "incomplete" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "warning" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "warning" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "notice" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "notice" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "deprecation" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "deprecation" / (1)
✓ parallel honors stop-on flags with worker recycling with dataset "skipped" / (0)
✓ parallel honors stop-on flags with worker recycling with dataset "skipped" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "failure" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "failure" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "defect" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "defect" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "error" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "error" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "risky" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "risky" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "incomplete" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "incomplete" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "warning" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "warning" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "notice" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "notice" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "deprecation" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "deprecation" / (1)
✓ parallel honors numeric stop-on thresholds with dataset "skipped" / (0)
✓ parallel honors numeric stop-on thresholds with dataset "skipped" / (1)
✓ parallel stop-on-defect includes errors warnings and risky tests with ('errors', 'failed', 2)
✓ parallel stop-on-defect includes errors warnings and risky tests with ('warns', 'warning', 0)
✓ parallel stop-on-defect includes errors warnings and risky tests with ('is risky', 'risky', 1)
✓ parallel stop-on-defect allows incomplete and skipped tests with ('is incomplete', 'incomplete')
✓ parallel stop-on-defect allows incomplete and skipped tests with ('is skipped', 'skipped')
✓ parallel does not count the same failure twice with (0)
✓ parallel does not count the same failure twice with (1)
✓ parallel counts issues hidden by the progress output with ('--stop-on-warning', 'has combined issues', 'failed', …)
✓ parallel counts issues hidden by the progress output with ('--stop-on-defect=2', 'has combined issues', 'failed', …)
✓ parallel counts issues hidden by the progress output with ('--stop-on-warning=2', 'has repeated warnings', 'warning', …)
✓ parallel counts issues hidden by the progress output with ('--stop-on-notice=2', 'has repeated notifications', 'notice', …)
✓ parallel stops only on the requested deprecation message with ('user deprecation', 1)
✓ parallel stops only on the requested deprecation message with ('another deprecation', 2)
✓ parallel honors stop-on flags from XML
✓ parallel CLI thresholds override XML stop-on flags
✓ parallel clamps empty and non-positive thresholds like PHPUnit with ('')
✓ parallel clamps empty and non-positive thresholds like PHPUnit with ('0')
✓ parallel clamps empty and non-positive thresholds like PHPUnit with ('-2')
✓ parallel counts a shared issue only once across recycled workers with ('warning', 'shares warning', 'warning')
✓ parallel counts a shared issue only once across recycled workers with ('defect', 'shares warning', 'warning')
✓ parallel counts a shared issue only once across recycled workers with ('notice', 'shares notice', 'notice')
✓ parallel combines stop-on counts from different workers and cleans up their files
PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
✓ allows to run a directory
@@ -2448,4 +2516,4 @@
✓ 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, 38 skipped, 1760 passed (3822 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1826 passed (4140 assertions)
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="../../../vendor/autoload.php" stopOnFailure="true">
<testsuites>
<testsuite name="parallel-stop-on">
<directory suffix="Test.php">ParallelStopOn</directory>
</testsuite>
</testsuites>
</phpunit>
@@ -0,0 +1,7 @@
<?php
it('deprecates', function () {
trigger_error('user deprecation', E_USER_DEPRECATED);
expect(true)->toBeTrue();
});
@@ -0,0 +1,5 @@
<?php
it('errors', function () {
throw new RuntimeException('boom');
});
@@ -0,0 +1,3 @@
<?php
it('fails', require __DIR__.'/../ParallelStopOnFailure.php');
@@ -0,0 +1,5 @@
<?php
it('is incomplete', function () {
$this->markTestIncomplete('work in progress');
});
@@ -0,0 +1,7 @@
<?php
it('notices', function () {
trigger_error('user notice', E_USER_NOTICE);
expect(true)->toBeTrue();
});
@@ -0,0 +1,5 @@
<?php
it('is risky', function () {
//
});
@@ -0,0 +1,7 @@
<?php
$issue = require __DIR__.'/../ParallelStopOnSharedIssue.php';
it('shares warning', $issue(E_USER_WARNING));
it('shares notice', $issue(E_USER_NOTICE));
@@ -0,0 +1,3 @@
<?php
it('is skipped')->skip('skipping');
@@ -0,0 +1,7 @@
<?php
it('warns', function () {
trigger_error('user warning', E_USER_WARNING);
expect(true)->toBeTrue();
});
@@ -0,0 +1,21 @@
<?php
it('has combined issues', function (): void {
trigger_error('combined warning', E_USER_WARNING);
expect(false)->toBeTrue();
});
it('has repeated warnings', function (): void {
trigger_error('first warning', E_USER_WARNING);
trigger_error('second warning', E_USER_WARNING);
expect(true)->toBeTrue();
});
it('has repeated notifications', function (): void {
trigger_error('first notice', E_USER_NOTICE);
trigger_error('second notice', E_USER_NOTICE);
expect(true)->toBeTrue();
});
@@ -0,0 +1,7 @@
<?php
it('deprecates', function () {
trigger_error('user deprecation', E_USER_DEPRECATED);
expect(true)->toBeTrue();
});
@@ -0,0 +1,5 @@
<?php
it('errors', function () {
throw new RuntimeException('boom');
});
@@ -0,0 +1,3 @@
<?php
it('fails', require __DIR__.'/../../ParallelStopOnFailure.php');
@@ -0,0 +1,5 @@
<?php
it('is incomplete', function () {
$this->markTestIncomplete('work in progress');
});
@@ -0,0 +1,7 @@
<?php
it('notices', function () {
trigger_error('user notice', E_USER_NOTICE);
expect(true)->toBeTrue();
});
@@ -0,0 +1,5 @@
<?php
it('is risky', function () {
//
});
@@ -0,0 +1,7 @@
<?php
$issue = require __DIR__.'/../../ParallelStopOnSharedIssue.php';
it('shares warning', $issue(E_USER_WARNING));
it('shares notice', $issue(E_USER_NOTICE));
@@ -0,0 +1,3 @@
<?php
it('is skipped')->skip('skipping');
@@ -0,0 +1,7 @@
<?php
it('warns', function () {
trigger_error('user warning', E_USER_WARNING);
expect(true)->toBeTrue();
});
@@ -0,0 +1,3 @@
<?php
it('passes 01')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 02')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 03')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 04')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 05')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 06')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 07')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 08')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 09')->assertTrue(true);
@@ -0,0 +1,3 @@
<?php
it('passes 10')->assertTrue(true);
@@ -0,0 +1,20 @@
<?php
return function (): void {
$barrier = getenv('PEST_TEST_STOP_BARRIER');
if ($barrier !== false) {
touch($barrier.'/worker-'.getenv('TEST_TOKEN'));
$deadline = microtime(true) + 10;
while (count(glob($barrier.'/worker-*')) < 2) {
if (microtime(true) >= $deadline) {
throw new RuntimeException('The second parallel worker did not reach the barrier.');
}
usleep(1000);
}
}
expect(false)->toBeTrue();
};
@@ -0,0 +1,7 @@
<?php
return static fn (int $severity): Closure => function () use ($severity): void {
trigger_error('shared issue', $severity);
expect(true)->toBeTrue();
};
+164
View File
@@ -0,0 +1,164 @@
<?php
use Symfony\Component\Process\Process;
$run = function (int $exitCode, array $arguments, array $environment = []): string {
$process = new Process(
['php', 'bin/pest', '--parallel', '--processes=1', '--order-by=default', '--fail-on-deprecation', ...$arguments, 'tests/Fixtures/Suites/ParallelStopOn'],
dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1', ...$environment],
);
$process->run();
$output = (string) removeAnsiEscapeSequences($process->getOutput());
expect($process->getExitCode())->toBe($exitCode, $process->getErrorOutput().$output)
->and($process->getErrorOutput())->toBeEmpty()
->and($output)->toMatch('/Tests:\s+\d+ [^\r\n]+\(\d+ assertions\)/');
return $output;
};
$outcomes = [
'failure' => ['failure', 'fails', 'failed', 1],
'defect' => ['defect', 'fails', 'failed', 1],
'error' => ['error', 'errors', 'failed', 2],
'risky' => ['risky', 'is risky', 'risky', 1],
'incomplete' => ['incomplete', 'is incomplete', 'incomplete', 0],
'warning' => ['warning', 'warns', 'warning', 0],
'notice' => ['notice', 'notices', 'notice', 0],
'deprecation' => ['deprecation', 'deprecates', 'deprecated', 1],
'skipped' => ['skipped', 'is skipped', 'skipped', 0],
];
test('parallel stop-on fixtures run completely without a stop flag', function (string $flag, string $name, string $outcome, int $exitCode) use ($run): void {
$output = $run($exitCode, ['--filter', "($name|passes)"]);
$plural = in_array($outcome, ['warning', 'notice'], true) ? $outcome.'s' : $outcome;
expect($output)->toContain("Tests: 2 $plural, 10 passed");
})->with(array_diff_key($outcomes, ['defect' => true]))->skipOnWindows();
test('parallel honors stop-on flags with worker recycling', function (string $flag, string $name, string $outcome, int $exitCode, int $batchSize) use ($run): void {
$output = $run($exitCode, ['--filter', "($name|passes)", "--stop-on-$flag", "--max-batch-size=$batchSize"]);
expect($output)->toContain("Tests: 1 $outcome (")
->not->toMatch('/\d+ passed/');
})->with($outcomes)->with([0, 1])->skipOnWindows();
test('parallel honors numeric stop-on thresholds', function (string $flag, string $name, string $outcome, int $exitCode, int $batchSize) use ($run): void {
$output = $run($exitCode, ['--filter', "($name|passes)", "--stop-on-$flag=2", "--max-batch-size=$batchSize"]);
$plural = in_array($outcome, ['warning', 'notice'], true) ? $outcome.'s' : $outcome;
expect($output)->toContain("Tests: 2 $plural (")
->not->toMatch('/\d+ passed/');
})->with($outcomes)->with([0, 1])->skipOnWindows();
test('parallel stop-on-defect includes errors warnings and risky tests', function (string $name, string $outcome, int $exitCode) use ($run): void {
$output = $run($exitCode, ['--filter', "($name|passes)", '--stop-on-defect', '--max-batch-size=1']);
expect($output)->toContain("Tests: 1 $outcome (")
->not->toMatch('/\d+ passed/');
})->with([
['errors', 'failed', 2],
['warns', 'warning', 0],
['is risky', 'risky', 1],
])->skipOnWindows();
test('parallel stop-on-defect allows incomplete and skipped tests', function (string $name, string $outcome) use ($run): void {
$output = $run(0, ['--filter', "($name|passes)", '--stop-on-defect']);
expect($output)->toContain("Tests: 2 $outcome, 10 passed");
})->with([
['is incomplete', 'incomplete'],
['is skipped', 'skipped'],
])->skipOnWindows();
test('parallel does not count the same failure twice', function (int $batchSize) use ($run): void {
$output = $run(1, ['--filter', '(fails|passes)', '--stop-on-failure=3', "--max-batch-size=$batchSize"]);
expect($output)->toContain('Tests: 2 failed, 10 passed');
})->with([0, 1])->skipOnWindows();
test('parallel counts issues hidden by the progress output', function (string $flag, string $name, string $outcome, int $exitCode) use ($run): void {
$output = $run($exitCode, ['--filter', "($name|passes)", $flag, '--max-batch-size=1']);
expect($output)->toContain("Tests: 1 $outcome (")
->not->toMatch('/\d+ passed/');
})->with([
['--stop-on-warning', 'has combined issues', 'failed', 1],
['--stop-on-defect=2', 'has combined issues', 'failed', 1],
['--stop-on-warning=2', 'has repeated warnings', 'warning', 0],
['--stop-on-notice=2', 'has repeated notifications', 'notice', 0],
])->skipOnWindows();
test('parallel stops only on the requested deprecation message', function (string $message, int $count) use ($run): void {
$output = $run(1, ['--filter', '(deprecates|passes)', "--stop-on-deprecation=$message", '--max-batch-size=1']);
expect($output)->toContain("Tests: $count deprecated");
if ($count === 1) {
expect($output)->not->toMatch('/\d+ passed/');
} else {
expect($output)->toContain('10 passed');
}
})->with([
['user deprecation', 1],
['another deprecation', 2],
])->skipOnWindows();
test('parallel honors stop-on flags from XML', function () use ($run): void {
$output = $run(1, ['--configuration=tests/Fixtures/Suites/ParallelStopOn.xml', '--filter', '(fails|passes)', '--max-batch-size=1']);
expect($output)->toContain('Tests: 1 failed (')
->not->toMatch('/\d+ passed/');
})->skipOnWindows();
test('parallel CLI thresholds override XML stop-on flags', function () use ($run): void {
$output = $run(1, ['--configuration=tests/Fixtures/Suites/ParallelStopOn.xml', '--filter', '(fails|passes)', '--stop-on-failure=2']);
expect($output)->toContain('Tests: 2 failed (')
->not->toMatch('/\d+ passed/');
})->skipOnWindows();
test('parallel clamps empty and non-positive thresholds like PHPUnit', function (string $threshold) use ($run): void {
$output = $run(1, ['--filter', '(fails|passes)', "--stop-on-failure=$threshold"]);
expect($output)->toContain('Tests: 1 failed (')
->not->toMatch('/\d+ passed/');
})->with(['', '0', '-2'])->skipOnWindows();
test('parallel counts a shared issue only once across recycled workers', function (string $flag, string $name, string $outcome) use ($run): void {
$output = $run(0, ['--filter', "($name|passes)", "--stop-on-$flag=2", '--max-batch-size=1']);
expect($output)->toMatch('/Tests:\s+\d+ '.$outcome.'s?, 10 passed/');
})->with([
['warning', 'shares warning', 'warning'],
['defect', 'shares warning', 'warning'],
['notice', 'shares notice', 'notice'],
])->skipOnWindows();
test('parallel combines stop-on counts from different workers and cleans up their files', function () use ($run): void {
$directory = sys_get_temp_dir().'/pest-stop-on-'.bin2hex(random_bytes(8));
mkdir($directory);
try {
$output = $run(
1,
['--processes=2', '--stop-on-failure=2', '--filter', '(fails|passes)', '--tmp-dir='.$directory],
['PEST_TEST_STOP_BARRIER' => $directory],
);
expect($output)->toContain('Tests: 2 failed')
->not->toContain('10 passed')
->not->toContain('did not reach the barrier')
->and(glob($directory.'/worker-*'))->toHaveCount(2)
->and(glob($directory.'/paratest_*'))->toBeEmpty();
} finally {
foreach (glob($directory.'/worker-*') as $file) {
unlink($file);
}
rmdir($directory);
}
})->skipOnWindows();