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

tests(smokehouse): always assert lhr.runtimeError #9130

Merged
merged 3 commits into from
Jun 6, 2019
Merged

Conversation

brendankenny
Copy link
Member

follow up to #9121 and part of the discussion from #8865. Adds two additional checks to smokehouse:

  • if Lighthouse exits with a non-zero exit code the lhr must have a runtimeError (or if there's a runtimeError it must have had a non-zero exit code). This just double checks the change in ff4f486#diff-8035764042a5861297234f1e1b922ca7R221 (and should always be 👍)
  • if there's a runtimeError in the run's LHR there must be a runtimeError in the expectations (slightly more strict than usual where something left out of the expectations isn't tested). We're asking everyone to keep an eye on runtimeError to spot problems, so our tests should be expecting them if one is in there :)

Since we weren't checking runtimeError before, it means error-expectations.js needs to be updated because those runs don't actually include a runtimeError (because the audit being run is a metric and doesn't need anything but base artifacts -- mentioned in the last bullet point of #8865 (review)).

Also does a drive-by fix to delete the smokehouse test artifact files after use. I was up to several hundred MBs of them in .tmp/ :)

runtimeError: {
code: 'ERRORED_DOCUMENT_REQUEST',
message: /Status code: 403/,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

has to be asserted now

@@ -194,7 +199,8 @@ function reportAssertion(assertion) {
} else {
if (assertion.diff) {
const diff = assertion.diff;
const fullActual = JSON.stringify(assertion.actual, null, 2).replace(/\n/g, '\n ');
const fullActual = String(JSON.stringify(assertion.actual, null, 2))
Copy link
Member Author

Choose a reason for hiding this comment

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

fixes the case when assertion.actual is undefined, which surprisingly I guess we've never encountered before because this throws on undefined.replace(...)

const lhr = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
const artifacts = assetSaver.loadArtifacts(artifactsDirectory);
Copy link
Member Author

Choose a reason for hiding this comment

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

we weren't loading the trace(s) and devtoolsLogs before, and I guess it's possible someone will want them at some point :) Regardless, switching to loadArtifacts is the better solution

*/
async function loadArtifacts(basePath) {
function loadArtifacts(basePath) {
Copy link
Member Author

Choose a reason for hiding this comment

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

fix to keep smokehouse's runLighthouse sync. Since we dropped the streaming JSON loader in #6099, this doesn't need to be async anyways

Copy link
Collaborator

Choose a reason for hiding this comment

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

runLighthouse needs to become async for #8962 (which still needs review btw :P)

Copy link
Member Author

Choose a reason for hiding this comment

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

runLighthouse needs to become async for #8962 (which still needs review btw :P)

ha, fair. Nothing is async in it anyways, though, so saves us a microtask or two :)

@brendankenny
Copy link
Member Author

added an audit that needs more than the base artifacts to the errors config so that the gathering runtimeErrors bubble up to the lhr for now

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -14,6 +14,8 @@ module.exports = {
maxWaitForLoad: 5000,
onlyAudits: [
'first-contentful-paint',
// TODO: this audit collects a non-base artifact, allowing the runtimeError to be collected.
Copy link
Collaborator

Choose a reason for hiding this comment

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

heh, yikes I forgot about that!

@@ -126,6 +126,11 @@ function makeComparison(name, actualResult, expectedResult) {
* @return {Smokehouse.Comparison[]}
*/
function collateResults(actual, expected) {
// If actual run had a runtimeError, expected *must* have a runtimeError.
// Relies on the fact that an `undefined` argument to makeComparison() can only match `undefined`.
const runtimeErrorAssertion = makeComparison('runtimeError', actual.lhr.runtimeError,
Copy link
Collaborator

Choose a reason for hiding this comment

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

doh! everything is off of lhr now we should just iterate through the keys

Copy link
Member Author

Choose a reason for hiding this comment

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

everything is off of lhr now we should just iterate through the keys

agreed, though I really want to make sure we check runtimeError, even if it's not in the expectations

artifacts = JSON.parse(fs.readFileSync(`${artifactsDirectory}/artifacts.json`, 'utf8'));
} catch (e) {}
// There should either be both an error exitCode and a lhr.runtimeError or neither.
if (!exitCode !== !lhr.runtimeError) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: there's a lot of ! to parse :)

Boolean(exitCode) !== Boolean(lhr.runtimeError)?

Copy link
Member Author

Choose a reason for hiding this comment

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

nit: there's a lot of ! to parse :)

Boolean(exitCode) !== Boolean(lhr.runtimeError)?

obviously we should go with if (!!(!!exitCode !== !!lhr.runtimeError))

(your suggestion sounds good :)

*/
async function loadArtifacts(basePath) {
function loadArtifacts(basePath) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

runLighthouse needs to become async for #8962 (which still needs review btw :P)

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

Successfully merging this pull request may close these issues.

3 participants