Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Random failure of the Process tests #9182

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

Closed
fabpot opened this issue Oct 1, 2013 · 7 comments
Closed

Random failure of the Process tests #9182

fabpot opened this issue Oct 1, 2013 · 7 comments
Labels

Comments

@fabpot
Copy link
Member

fabpot commented Oct 1, 2013

Since a while now, the Process test suite randomly fails with error messages like the following one:

1) Symfony\Component\Process\Tests\SigchildDisabledProcessTest::testProcessPipes with data set #8 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 4096)
Failed asserting that 4145152 matches expected 4194305.
/home/travis/build/symfony/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:113

ping @romainneutron

@romainneutron
Copy link
Contributor

I actually thought it was just happening on windows platform when using file handles (see https://bugs.php.net/bug.php?id=65650 that produces the same test failure)

I'm gonna dig this, any help would be very appreciated

@romainneutron
Copy link
Contributor

Okay, I've run the test suite in 2.2 / 2.3 / master on my computer (OSX) and a desktop ubuntu intensively. I got everytime the same results (many many many tries) :

$ ~ phpunit --filter=testProcessPipes --repeat=200 Tests/SimpleProcessTest.php
PHPUnit 3.8-g55a6dd0 by Sebastian Bergmann.

Configuration read from /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/phpunit.xml.dist

The Xdebug extension is not loaded. No code coverage will be generated.

.............................................................   61 / 2000 (  3%)
.............................................................  122 / 2000 (  6%)
.............................................................  183 / 2000 (  9%)
.............................................................  244 / 2000 ( 12%)
.............................................................  305 / 2000 ( 15%)
.............................................................  366 / 2000 ( 18%)
.............................................................  427 / 2000 ( 21%)
.............................................................  488 / 2000 ( 24%)
.............................................................  549 / 2000 ( 27%)
.............................................................  610 / 2000 ( 30%)
.............................................................  671 / 2000 ( 33%)
.............................................................  732 / 2000 ( 36%)
.............................................................  793 / 2000 ( 39%)
.............................................................  854 / 2000 ( 42%)
.............................................................  915 / 2000 ( 45%)
.............................................................  976 / 2000 ( 48%)
............................................................. 1037 / 2000 ( 51%)
............................................................. 1098 / 2000 ( 54%)
............................................................. 1159 / 2000 ( 57%)
............................................................. 1220 / 2000 ( 61%)
............................................................. 1281 / 2000 ( 64%)
............................................................. 1342 / 2000 ( 67%)
............................................................. 1403 / 2000 ( 70%)
............................................................. 1464 / 2000 ( 73%)
............................................................. 1525 / 2000 ( 76%)
............................................................. 1586 / 2000 ( 79%)
............................................................. 1647 / 2000 ( 82%)
............................................................. 1708 / 2000 ( 85%)
............................................................. 1769 / 2000 ( 88%)
............................................................. 1830 / 2000 ( 91%)
............................................................. 1891 / 2000 ( 94%)
............................................................. 1952 / 2000 ( 97%)
................................................

Time: 7.46 minutes, Memory: 4531.75Mb

Tests are okay. Please note the amount of memory used (thats another issue).

I started to become desperate when I got these failures :

$ ~ phpunit --filter=testProcessPipes --repeat=200 Tests/SimpleProcessTest.php
PHPUnit 3.8-g55a6dd0 by Sebastian Bergmann.

Configuration read from /Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/phpunit.xml.dist

The Xdebug extension is not loaded. No code coverage will be generated.

.............................................................   61 / 2000 (  3%)
.............................................................  122 / 2000 (  6%)
.............................................................  183 / 2000 (  9%)
.............................................................  244 / 2000 ( 12%)
.............................................................  305 / 2000 ( 15%)
.............................................................  366 / 2000 ( 18%)
.............................................................  427 / 2000 ( 21%)
.............................................................  488 / 2000 ( 24%)
...........................F.................................  549 / 2000 ( 27%)
.............................................................  610 / 2000 ( 30%)
......................F......................................  671 / 2000 ( 33%)
.............................................................  732 / 2000 ( 36%)
.............................................................  793 / 2000 ( 39%)
.............................................................  854 / 2000 ( 42%)
.............................................................  915 / 2000 ( 45%)
.............................................................  976 / 2000 ( 48%)
............................................................. 1037 / 2000 ( 51%)
.........F................................................F.. 1098 / 2000 ( 54%)
.............................F............................... 1159 / 2000 ( 57%)
............................................................. 1220 / 2000 ( 61%)
............................................................. 1281 / 2000 ( 64%)
............................................................. 1342 / 2000 ( 67%)
....................F........................................ 1403 / 2000 ( 70%)
............................................................. 1464 / 2000 ( 73%)
.........................................F..........FF....... 1525 / 2000 ( 76%)
............................................................. 1586 / 2000 ( 79%)
............................................................. 1647 / 2000 ( 82%)
............................................................. 1708 / 2000 ( 85%)
............................................................. 1769 / 2000 ( 88%)
............................................................. 1830 / 2000 ( 91%)
............................................................. 1891 / 2000 ( 94%)
............................................................. 1952 / 2000 ( 97%)
..................................F.............

Time: 13.74 minutes, Memory: 4527.25Mb

There were 10 failures:

1) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #5 ('include \'/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php\';', 64)
Failed asserting that 24576 matches expected 65537.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

2) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #2 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 16)
Failed asserting that 16384 matches expected 16385.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

3) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #6 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 1024)
Failed asserting that 1032192 matches expected 1048577.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:117

4) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #5 ('include \'/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php\';', 64)
Failed asserting that 16384 matches expected 65537.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

5) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #7 ('include \'/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php\';', 1024)
Failed asserting that 999424 matches expected 1048577.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

6) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #2 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 16)
Failed asserting that 8192 matches expected 16385.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

7) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #5 ('include \'/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php\';', 64)
Failed asserting that 65536 matches expected 65537.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:116

8) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #6 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 1024)
Failed asserting that 1032192 matches expected 1048577.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:117

9) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #7 ('include \'/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/PipeStdinInStdoutStdErrStreamSelect.php\';', 1024)
Failed asserting that 1015808 matches expected 1048577.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:117

10) Symfony\Component\Process\Tests\SimpleProcessTest::testProcessPipes with data set #6 ('fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);', 1024)
Failed asserting that 1048576 matches expected 1048577.

/Users/romain/Documents/workspace/symfony/src/Symfony/Component/Process/Tests/AbstractProcessTest.php:117

FAILURES!                                   
Tests: 2000, Assertions: 3994, Failures: 10.

Yes, I got it. The issue occurs when the cpu is under heavy load. The bug can be reproduce by running the test suite with the mentioned arguments --filter=testProcessPipes --repeat=200 Tests/SimpleProcessTest.php and running a composer update on a huge composer.json file and dev stability :)

I'm continuing to investigate

@cmerot
Copy link

cmerot commented Oct 9, 2013

I have the same random bug :(
On my computer this code almost always fails (it's ok after 10 retries). If that can help...

<?php
require 'vendor/autoload.php';
use Symfony\Component\Process\Process;

$cmd = "git show 'master':composer.json";
$cwd = "/home/co/apps/my-repo-with-a-big-composer.json/";
$process = new Process($cmd, $cwd);
$process->run();
print $process->getOutput();

@romainneutron
Copy link
Contributor

I got a pending fix, linux only. Currently working on the windows compatibility

romainneutron added a commit to romainneutron/symfony that referenced this issue Oct 9, 2013
fabpot added a commit that referenced this issue Oct 9, 2013
…mainneutron)

This PR was merged into the 2.2 branch.

Discussion
----------

[Process][2.2] Fix 9182 : random failure on pipes tests

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9182
| License       | MIT

I'm not a big fan of this fix, but - at least - it works.

With this code, finally, Process does not behave the same at all on Windows and Linux.
This patch does not smells very good but it solves the random failing test issue (that produced at runtime too).

Actually, calling `proc_get_status` within the waiting loop introduced the bug.
So this PR reverts to the previous behavior (consider a process running as long as pipes give data). On Windows, this is not the same behavior as we're not using streams but file handles. Whereas the feof of a stream is detected when the other side closes, the feof of a file handle can be reached at any time. So, on Windows, `proc_get_status` is called (checking the feof of the file handle might be positive until the executable outputs something), and we consider a process running as long as the information returned says it's running.

We could think of decouple windows and linux logic in two separated objects, using the interfaces I introduced in #8753. This could bring much more readability and make the code more easy to understand.

Commits
-------

64a0b40 [Process] Fix #9182 : random failure on pipes tests
@fabpot fabpot closed this as completed Oct 9, 2013
fabpot added a commit that referenced this issue Oct 9, 2013
* 2.2:
  [Process] Fix #9182 : random failure on pipes tests
  Fixed propel guessed relations
  [FramworkBundle][HttpKernel] Check event listener services are not abstract
  fixed CS
  Check for lock existence before unlinking
  [FrameworkBundle] fixed path replacement on Windows

Conflicts:
	src/Symfony/Component/Process/Process.php
fabpot added a commit that referenced this issue Oct 9, 2013
* 2.3:
  [Process] Fix #9182 : random failure on pipes tests
  Fixed propel guessed relations
  [FramworkBundle][HttpKernel] Check event listener services are not abstract
  fixed CS
  Check for lock existence before unlinking
  remove MinCount and MaxCount contraints. It has been replaced by Count constraints.
  [FrameworkBundle] fixed path replacement on Windows

Conflicts:
	src/Symfony/Bridge/Propel1/Tests/Form/PropelTypeGuesserTest.php
@fabpot
Copy link
Member Author

fabpot commented Oct 9, 2013

apparently, I messed up the merge to the 2.3 branch.

@romainneutron
Copy link
Contributor

If you have few min (maybe an hour) I'll take care of it

fabpot added a commit that referenced this issue Oct 10, 2013
This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Fix latest merge from 2.2 in 2.3

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes (Process tests are okay)
| License       | MIT

Fix latest merge from 2.2 in 2.3, see #9182

Process tests are okay, an error in HttpKernel seems to occur

Commits
-------

b5e3576 [Process] Fix latest merge from 2.2 in 2.3
parsingphase pushed a commit to parsingphase/satis that referenced this issue Nov 1, 2013
Update the symfony process library which causes missing branches in
satis due to this issue - symfony/symfony#9182
@halaei
Copy link

halaei commented May 9, 2020

Hi there. I think the related commit to this fix, 64a0b40, has something to do with this issue:

Process AbstractPipes.php infinite fwrite() loop on error #21580

Maybe $this->isRunning() should be called for Linux inside wait() function as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants