-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
PHPUnit process is blocked when there's a lot of output and a test with separate process #6003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 10.5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,12 +12,15 @@ | |||||
use function array_merge; | ||||||
use function fclose; | ||||||
use function file_put_contents; | ||||||
use function fread; | ||||||
use function fwrite; | ||||||
use function is_array; | ||||||
use function is_resource; | ||||||
use function proc_close; | ||||||
use function proc_open; | ||||||
use function stream_get_contents; | ||||||
use function proc_terminate; | ||||||
use function sprintf; | ||||||
use function stream_select; | ||||||
use function sys_get_temp_dir; | ||||||
use function tempnam; | ||||||
use function unlink; | ||||||
|
@@ -112,16 +115,64 @@ protected function runProcess(string $job, array $settings): array | |||||
|
||||||
$stderr = $stdout = ''; | ||||||
|
||||||
if (isset($pipes[1])) { | ||||||
$stdout = stream_get_contents($pipes[1]); | ||||||
unset($pipes[0]); | ||||||
$timeout = 5; | ||||||
|
||||||
fclose($pipes[1]); | ||||||
} | ||||||
while (true) { | ||||||
$r = $pipes; | ||||||
$w = null; | ||||||
$e = null; | ||||||
|
||||||
$n = @stream_select($r, $w, $e, $timeout); | ||||||
|
||||||
if ($n === false) { | ||||||
break; | ||||||
} | ||||||
|
||||||
if ($n === 0) { | ||||||
proc_terminate($process, 9); | ||||||
|
||||||
throw new PhpProcessException( | ||||||
sprintf( | ||||||
'Job execution aborted after %d seconds', | ||||||
$timeout, | ||||||
), | ||||||
); | ||||||
} | ||||||
|
||||||
if (isset($pipes[2])) { | ||||||
$stderr = stream_get_contents($pipes[2]); | ||||||
if ($n > 0) { | ||||||
foreach ($r as $pipe) { | ||||||
$pipeOffset = 0; | ||||||
|
||||||
fclose($pipes[2]); | ||||||
foreach ($pipes as $i => $origPipe) { | ||||||
if ($pipe === $origPipe) { | ||||||
$pipeOffset = $i; | ||||||
|
||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
if (!$pipeOffset) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
break; | ||||||
} | ||||||
|
||||||
$line = fread($pipe, 8192); | ||||||
|
||||||
if ($line === '' || $line === false) { | ||||||
fclose($pipes[$pipeOffset]); | ||||||
|
||||||
unset($pipes[$pipeOffset]); | ||||||
} elseif ($pipeOffset === 1) { | ||||||
$stdout .= $line; | ||||||
} else { | ||||||
$stderr .= $line; | ||||||
} | ||||||
} | ||||||
|
||||||
if (empty($pipes)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
break; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
proc_close($process); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
https://github.com/sebastianbergmann/phpunit/issues/5993 | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = '--debug'; | ||
$_SERVER['argv'][] = __DIR__ . '/5993/Issue5993Test.php'; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
%A | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect the exact exception asserted here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
PHPUnit process is blocked when there's a lot of output and a test with separate process | ||
--INI-- | ||
error_reporting=-1 | ||
display_errors=1 | ||
display_startup_errors=1 | ||
memory_limit=-1 | ||
zend.assertions=1 | ||
assert.exception=1 | ||
--SKIPIF-- | ||
<?php | ||
for ($i = 0; $i < 390; $i++) { | ||
\trigger_error("error {$i}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all the inis needed? Isn't standard long fwrite to stderr/stdout enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want to assist in fixing this problem, you could try to reduce the reproducer to a very minimum. we suppose the problem is a underlying php-src bug and having a reproducer small enough to report to the php-src project would be valuable - so at best getting something which no longer depends on PHPUnit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the main or the child blocked? If the main (reading) process, then output to long stdout/stderr must be enough. If the child process, then I do not understand the problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 3 processes are involved. Needs further investigation phpunit main -> PHPT |
||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
use PHPUnit\Framework\Attributes\RunInSeparateProcess; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class Issue5993Test extends TestCase | ||
{ | ||
#[RunInSeparateProcess] | ||
public function testOne(): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.