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 #9481: fix invalid output during environment initialization #9633
Conversation
Build PASSEDStarted: 2018-03-09 14:49:06 View more information about this build on: |
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.
I think the changes in formatters.py
make sense, but the way that we are ensuring that the logger is shutdown doesn't really work.
@@ -133,3 +133,4 @@ def __exit__(self, *args, **kwargs): | |||
pass | |||
self.logging_queue.close() | |||
self.logger.info("queue closed") | |||
self.logger.shutdown() |
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.
So, I don't think this is going to work. Sometimes we (hackily?) run multiple session with the same logger (e.g. for stability checking). I think you need to look for all the places in the code where we call setup_logging
and ensure that each of those places has a corresponding call to logger.shutdown()
once the logger is no longer in use.
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.
But don't you think that if a command, like mentioned in original issue, is going to fail, then the control will never return to the place, where I have called setup_logging
, so even if I define the shutdown function at each place, the logger will not shut down properly and nothing will be written to the log file. The command fails at the environment variable initialization part in the wptrunner.py
file, and that was the reason that the suite_end()
function was never called. Also, I could not understand what you want to say when you mention about run multiple session with the same logger? If you could provide a command which gives such scenario, that would be a great help for testing.
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.
I think that you want to change the call in wptlogging.py
for successful calls only. When the tests fail, the call in wptrunner.py
will call the shutdown()
method and write to the file correctly. But when the test cases succeed, the control will reach the end, and hence the shutdown()
calls will also execute. If this is what you want me to do, then I think, I agree with you here. I'll do the necessary changes. If not, please elaborate your opinion about the problem.
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.
So when there's an exception the stack will unwind, but we'll still have the oppertunty to execute exception handlers and finally cluases in each calling function.
The way that the logger is used isn't ideal because we tend to call setup_logging
and set a global, but it's quite possible to ensure that we have a try/finally
block enclosing the scope over which the logger is actually used, and calling shotdown if we exit that scope even via an exception.
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.
Hi, sorry for the delay. I have updated the code to wrap all the setup_logging
calls in try/finally
blocks. I have kept my previous logic of calling shutdown()
in wptlogging.py
's CaptureIO
class as without that nothing was being written to the empty.json
file. Please review and give suggestions.
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.
I think the way this works in run.py
is more or less right, but there are a couple of other places that will break without similar changes. In wptrunner.py
itself the main
function sets up a mozlog logger. In tools/ci/check_stability.py
we create a logger in run
. There are a few other places you can see in the search at https://github.com/w3c/web-platform-tests/search?utf8=%E2%9C%93&q=setup_logging&type=
In all these cases we need to ensure that the shutdown method is being called when the logger's no longer in use.
logger.suite_end() | ||
return unexpected_total == 0 | ||
|
||
return unexpected_count == 0 |
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.
I don't think this change is right; we certainly want to still call suite_end.
tools/wpt/run.py
Outdated
rv = run_single(venv, **kwargs) > 0 | ||
except Exception as e: | ||
logger.error(e) | ||
logger.shutdown() |
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.
This should be in a finally
block.
How do I test these changes? Can you tell some particular test cases, where these changes might fail? Or shall I run the complete test suite? |
So if you run e.g. |
Earlier the logger was emitting an empty JSON file for errors during environment initialization. Now the mozlog shutdown() method is called if the environment initialization fails to ensure that the generated report file contains valid JSON object. The suite_end() method functionality has been moved to the shutdown function to avoid redundancy.
OK, I think this is good now, thanks. Let's merge it and find out if anything unexpectedly breaks. |
This seems to have broken Travis: see https://travis-ci.org/w3c/web-platform-tests/jobs/352369551 and https://travis-ci.org/w3c/web-platform-tests/jobs/352369562, for example.
|
How did my changes pass Travis test, in this case? @jgraham shall I push more commits to fix this, or do I need to create a new pull request? |
I don't think you can push more commits and reopen this PR, so could you please create a new pull request? |
How do I check if there are issues at other places also? Tox passes without showing any errors. |
Sorry, that's my fault. It looks like the logger in |
@jgraham why did the automatic running of |
Because that doesn't run in the stability checker, just using normal |
@jgraham what would it take to have some unit tests for the stability checker? |
Earlier the logger was emitting an empty JSON file for errors during
environment initialization. Now the mozlog shutdown() method is called
if the environment initialization fails to ensure that the generated report
file contains valid JSON object. The suite_end() method functionality
has been moved to the shutdown function to avoid redundancy.
This change is