Skip to content
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

[Process] Fixed fatal errors in getOutput and getErrorOutput when process was not started #10480

Merged
merged 2 commits into from
Mar 18, 2014

Conversation

romainneutron
Copy link
Contributor

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

This PR replaces #9452 and address the latest changes.
Side note : I've not updated getExitCode, getExitCodeText and isSuccessful as they were explicitly tested to return null in case the process is not started or terminated. I think it would be a BC break to do that.

@stof
Copy link
Member

stof commented Mar 18, 2014

shouldn't we add tests covering this ?

*
* @throws LogicException If the process has not run.
*/
private function requireProcessHasRun($functionName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would name it requireProcessIsStarted just as $this->isStarted()

@romainneutron
Copy link
Contributor Author

@stof what tests are missing ? It seems everything is unit tested in this PR, isn't it ?

@romainneutron
Copy link
Contributor Author

@Tobion comment addressed

@stof
Copy link
Member

stof commented Mar 18, 2014

well, the case which are currently throwing a fatal error are not tested.

} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Process\Exception\LogicException', $e);
$this->assertEquals(sprintf('Process must be terminated before calling %s.', $method), $e->getMessage());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will not fail if the exception is not triggered (try returning null instead of triggering the exception and you will see it pass)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside what @stof said, why not catching the LogicException as opposed to asserting what's the type? The current catch block will also catch any PhpUnit exceptions (like those thrown on warnings). There should be $this->fail() call after call_user_func().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about having a proper Process::stop call in case the exception is not the expected one (last line of the test)

@romainneutron
Copy link
Contributor Author

PR updated, comments addressed

*
* @see http://tldp.org/LDP/abs/html/exitcodes.html
* @see http://en.wikipedia.org/wiki/Unix_signal
*/
public function getExitCodeText()
{
if (null === $this->exitcode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is problematic since it does not call updateStatus before.
IMO it's better to remove this and add below

$exitcode = $this->getExitCode();

if (null === $exitcode) {
return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, it's now fixed

@Tobion
Copy link
Member

Tobion commented Mar 18, 2014

+1

fabpot added a commit that referenced this pull request Mar 18, 2014
…ut when process was not started (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Fixed fatal errors in getOutput and getErrorOutput when process was not started

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

This PR replaces #9452 and address the latest changes.
Side note : I've not updated `getExitCode`, `getExitCodeText` and `isSuccessful` as they were explicitly tested to return null in case the process is not started or terminated. I think it would be a BC break to do that.

Commits
-------

449fe01 [Process] Trow exceptions in case a Process method is supposed to be called after termination
0ae6858 [Process] fixed fatal errors in getOutput and getErrorOutput when process was not started
@fabpot fabpot merged commit 449fe01 into symfony:2.3 Mar 18, 2014
@romainneutron romainneutron deleted the fix_fatals branch March 18, 2014 18:04
public function testExitCodeTextIsNullWhenExitCodeIsNull()
{
$process = $this->getProcess('');
$this->assertNull($process->getExitCodeText());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainneutron I get a failure on Windows 7, PHP 5.5.3, Mingw:

Symfony\Component\Process\Exception\RuntimeException: This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I got it : #10483

@Tobion
Copy link
Member

Tobion commented Mar 18, 2014

I wonder why Process::restart does throw new RuntimeException('Process is already running');

Restart to me means stop() followed by start(). Why must the process be finished before restarting? Does not seem logical to me.

Compare: If you have a countdown you want to restart, I would not expect that I need to wait until it's done before I may restart the countdown.

fabpot added a commit that referenced this pull request Mar 18, 2014
…onment (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Process] Fix unit tests in sigchild disabled environment

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

We've been a bit fast when merging #10480 and tests were broken in the last update I did.

Commits
-------

5f6ee12 [Process] Fix unit tests in sigchild disabled environment
@Tobion
Copy link
Member

Tobion commented Mar 18, 2014

Also I wonder why hasBeenSignaled throws RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.').
From what I see in code, when sigchild is enabled, only termsig cannot be retrived but whether it has been signaled is still known?!

@Tobion
Copy link
Member

Tobion commented Mar 18, 2014

Also Process::start() RuntimeException('Process is already running') should be a LogicException as well to be consistent. But that would be a tiny BC break.

@romainneutron
Copy link
Contributor Author

@Tobion your comment makes sense about the exception thrown in Process::restart. It's been introduced in #5456. I dont see any reason why we can not stop the process instead of throwing an exception, but it would be a BC break

About hasBeenSignaled, when I did tests on PHP compiled with --enable-sigchild, it seems it was the result I had. I'll test it again.

@Tobion
Copy link
Member

Tobion commented Mar 18, 2014

I just wonder that hasBeenSignaled cannot access $this->processInformation['signaled']; but then in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L355 it is accessed which is not consistent.

fabpot added a commit that referenced this pull request Mar 19, 2014
…tests in sigchild environment (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Process] Remove unreachable code + avoid skipping tests in sigchild environment

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

As mentioned by @Tobion in #10480 (comment), I removed the dead code. I also fixed/updated the test suite on PHP compiled with `--enable-sigchild`.

Commits
-------

d52dd32 [Process] Remove unreachable code + avoid skipping tests in sigchild environment
fabpot added a commit to symfony/process that referenced this pull request Mar 19, 2014
…tests in sigchild environment (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Process] Remove unreachable code + avoid skipping tests in sigchild environment

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

As mentioned by @Tobion in symfony/symfony#10480 (comment), I removed the dead code. I also fixed/updated the test suite on PHP compiled with `--enable-sigchild`.

Commits
-------

d52dd32 [Process] Remove unreachable code + avoid skipping tests in sigchild environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants