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
🏗 Silence subprocesses in visual diffs by default #16704
🏗 Silence subprocesses in visual diffs by default #16704
Conversation
Codecov Report
@@ Coverage Diff @@
## master #16704 +/- ##
==========================================
- Coverage 78.12% 78.09% -0.04%
==========================================
Files 553 553
Lines 40336 40325 -11
==========================================
- Hits 31513 31492 -21
- Misses 8823 8833 +10
Continue to review full report at Codecov.
|
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.
A few comments below.
build-system/tasks/visual-diff.js
Outdated
process.env.WEBSERVER_QUIET = ''; | ||
argv.chrome_debug = true; // eslint-disable-line google-camelcase/google-camelcase | ||
argv.gulp_debug = true; // eslint-disable-line google-camelcase/google-camelcase | ||
argv.webserver_debug = true; // eslint-disable-line google-camelcase/google-camelcase |
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 you can avoid having to disable the camel case warning by using argv['chrome_debug']
, etc.
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.
Thank the heavens
build-system/exec.js
Outdated
@@ -62,9 +62,10 @@ exports.execScriptAsync = function(script, options) { | |||
* Executes the provided command, and terminates the program in case of failure. | |||
* | |||
* @param {string} cmd Command line to execute. | |||
* @param {<Object>} options extra options send to the process. |
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.
nit: Extra options to send to the process
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.
Done
build-system/tasks/visual-diff.js
Outdated
// The child node process has an asynchronous stdout. See #10409. | ||
await sleep(100); | ||
} | ||
process.exit(); |
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.
process.exit()
doesn't do a clean exit, and could cause stray console output to be printed after the gulp
process has printed its completion status. I see that you're doing a sleep
after killing webServerProcess
to avoid this.
A better way to signal task completion is to return a promise or call done()
. If the exit code needs to be something other than 0
, you can set the value of process.exitCode
before signaling task completion.
Having said that, I'm not even sure you need to call process.exit
here, since there's nothing more to do after returning from 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.
What is this "done" that you're talking about? I saw it in tests but not in any of the gulp files
Unfortunately the process doesn't exit unless I explicitly call process.exit(), for some reason
My guess is that somehow the child processes are hanging it. I'd be happy if you can help me figure this out! I want the process to exit cleanly...
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.
done
is just a callback you can pass to a gulp task (can be called anything). Look up the gulp 3.9 docs.
For the child task, you could try sending it a kill instead of an int, and then call done in the main task. If all that fails, add a TODO.
build-system/tasks/visual-diff.js
Outdated
@@ -306,7 +319,8 @@ function cleanupAmpConfig() { | |||
log('verbose', 'Cleaning up existing AMP config'); | |||
AMP_RUNTIME_TARGET_FILES.forEach(targetFile => { | |||
execOrDie( | |||
`gulp prepend-global --local_dev --target ${targetFile} --remove`); | |||
`gulp prepend-global --local_dev --target ${targetFile} --remove`, | |||
getStdioOptions(argv.gulp_debug)); |
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.
gulp prepend-global
doesn't really print any useful info, so I'm not convinced that the gulp_debug
flag is necessary. (The log('verbose')
above should be sufficient.)
I think you can simply pass in {'stdio': 'ignore'}
here.
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.
Done
build-system/tasks/visual-diff.js
Outdated
`gulp prepend-global --local_dev --target ${targetFile} ` + | ||
`--${config}`); | ||
`gulp prepend-global --local_dev --target ${targetFile} --${config}`, | ||
getStdioOptions(argv.gulp_debug)); |
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.
Same comment as above.
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.
Done
build-system/tasks/visual-diff.js
Outdated
@@ -116,7 +116,7 @@ function setPercyBranch() { | |||
async function launchWebServer() { | |||
const gulpServeAsync = execScriptAsync( | |||
`gulp serve --host ${HOST} --port ${PORT} ${process.env.WEBSERVER_QUIET}`, | |||
{stdio: 'inherit'}); | |||
getStdioOptions(argv.gulp_debug || argv.webserver_debug)); | |||
|
|||
gulpServeAsync.on('exit', code => { | |||
if (code != 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'm seeing an error code of null
being returned by gulp serve
in the .on('exit', ...)
handler: https://travis-ci.org/ampproject/amphtml/jobs/403246979#L627
[18:55:04] ERROR: 'serve' errored with code null. Cannot continue with visual diff tests
From the spawn
documentation, it appears you should be handling errors in .on('close', ...)
and not .on('exit', ...)
.
build-system/tasks/visual-diff.js
Outdated
@@ -116,7 +116,7 @@ function setPercyBranch() { | |||
async function launchWebServer() { | |||
const gulpServeAsync = execScriptAsync( | |||
`gulp serve --host ${HOST} --port ${PORT} ${process.env.WEBSERVER_QUIET}`, | |||
{stdio: 'inherit'}); | |||
getStdioOptions(argv.gulp_debug || argv.webserver_debug)); |
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 server output should depend only on whether webserver_debug
is enabled. This could be simplified to:
{'stdio': argv.webserver_debug ? 'inherit' : 'ignore'},
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.
Sure, but in this case argv.gulp_debug becomes useless. I'll remove it too :)
build-system/tasks/visual-diff.js
Outdated
* @param {boolean} shouldPrint true if the sub-process should print its output | ||
* @return {<Object>} sub-process options | ||
*/ | ||
function getStdioOptions(shouldPrint) { |
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 function is required. See other comments.
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.
Done
build-system/tasks/visual-diff.js
Outdated
* @param {!ChildProcess} webServerProcess the webserver process to shut down. | ||
*/ | ||
async function shutdown(webServerProcess) { | ||
if (webServerProcess.exitCode == null) { |
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.
Is this check meant to see if webServerProcess
is still running? If so, I think you can use webServerProcess.connected
. See reference.
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 failed to figure this out, and since the current code, fragile as it might be, "works™", I just added a TODO in your name to figure this out :)
build-system/exec.js
Outdated
@@ -62,7 +62,7 @@ exports.execScriptAsync = function(script, options) { | |||
* Executes the provided command, and terminates the program in case of failure. | |||
* | |||
* @param {string} cmd Command line to execute. | |||
* @param {<Object>} options extra options send to the process. | |||
* @param {<Object>} options Extra options send to the process. |
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.
The nit was that you were missing to
before send
:)
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.
🙄🙄🙄
Per this comment: #16541 (comment)