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

Fix race condition in test harness #1173

Merged
merged 1 commit into from
Dec 4, 2019
Merged

Conversation

jpwhite4
Copy link
Member

@jpwhite4 jpwhite4 commented Dec 2, 2019

The unit tests were not passing in my docker. The reason was because there is no guarantee that the process has exited by the time the proc_get_status() function is called. So the test would fail if the process was still in the running state when the status function was executed.

This change removes the proc_get_status() call and instead uses the return value from the proc_close which is guaranteed to give a yes/no answer.

@jpwhite4 jpwhite4 added this to the 9.0.0 milestone Dec 2, 2019
@jpwhite4 jpwhite4 added the qa / testing Updates/additions to tests label Dec 2, 2019
while ( ! feof($this->pipes[2]) ) {
$errorMessage .= fgets($this->pipes[2]);
}
if ($exitStatus !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how accurate this is, but the proc_close documentation states that:

Returns the termination status of the process that was run. In case of an error then -1 is returned.

I don't know if it's possible that a value other than 0 or -1 is returned, but elsewhere I've written code that explicitly compares against -1.

Copy link
Member Author

@jpwhite4 jpwhite4 Dec 3, 2019

Choose a reason for hiding this comment

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

exit status can be a range of values not just 0 or -1. The unit tests have a 127 and a 1 return values (this can be seen in the logs).

[edit to add]

.. of the unit tests

2019-12-02 20:27:56 [error] Error 2 executing external filter process: sh: 1: Syntax error: "(" unexpected
2019-12-02 20:27:56 [error] Error 127 executing external filter process: sh: 1: gobbledygook: not found

while (($buffer = fgets($this->pipes[2])) !== false) {
$errorOutput .= $buffer;
}
fclose($this->pipes[2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that anything additional could be written to STDOUT and STDERR between here and the proc_close below? I'm curious if this can be put after the proc_close, but I've never tried that.

Copy link
Member Author

Choose a reason for hiding this comment

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

The docs state that you should close all open file handles before the proc_close to avoid deadlocks. Since STDERR is read until EOF (or error) then you shouldn't get any more data out of stderr. Any data sitting in the stdout buffer will get thrown away, but this should be handled by the code starting on line 121.

If you add a filter that writes an infinite amount of data to stderr after stdin is closed then the proc_close() call will never execute. Don't do this.

@jpwhite4 jpwhite4 merged commit 730b18f into ubccr:xdmod9.0 Dec 4, 2019
@jpwhite4 jpwhite4 deleted the unit_race branch December 4, 2019 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qa / testing Updates/additions to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants