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): run smoketests in parallel #4748

Merged
merged 22 commits into from
Apr 11, 2018
Merged

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Mar 13, 2018

From 149s (2.5 minutes!) down to 45s!

Mostly a matter of running them in parallel.

Changes

  • Replaced those gnarly run-test.sh scripts with a flexible JS-based smoketest runner. Runs each smokehouse.js invocation in its own child-process.
  • Moved a run of dbw-expectations into offline, as it was testing the exact same URL, just asserting different aspects out the output.
  • yarn smoke will run all, but you can do yarn smoke byte and yarn smoke byte ttci to run individual smokehouse expectations
  • Split the PWA smoketests into two files (pwa and pwa2), as they were some of the slowest smoketests we did.
  • yarn smokehouse was removed. it's effectively replaced with yarn smoke pwa && yarn smoke pwa2
  • Restore the shop.polymer-project.org smoketest.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

this seems good most of the time, but I am concerned about the debuggability if something does go wrong and the output is all interleaved together :)

also, whats the feasibility of getting rid of all the run-tests.sh files for just one :)

@paulirish
Copy link
Member Author

I am concerned about the debuggability if something does go wrong and the output is all interleaved together :)

Aye. I added an extra line of output where "checking " is emitted right before the assertions are checked. IMO i think that lowers the probability of confusing results a LOT. But it's still possible and to fix that means buffering output which means any failures you won't see until ALL smoketests are done. Also requires lots more work. :)

also, whats the feasibility of getting rid of all the run-tests.sh files for just one :)

And going to JS? Mmmmmmm that's also an option.

@paulirish
Copy link
Member Author

@patrickhulce (no rush, but..) thoughts? right now it looks like this work will go into ❄️ chillin state.

@brendankenny
Copy link
Member

And going to JS? Mmmmmmm that's also an option.

shelljs is somewhat active again so could work ok for this (and get us easier windows support)

@paulirish
Copy link
Member Author

TBH it could move to JS without shelljs, even. really not too terrible.

@wardpeet
Copy link
Collaborator

100% js would be nice.

For now we could still buffer the output inside a variable and output it where needed if we are afraid of debugging.

@paulirish
Copy link
Member Author

For now we could still buffer the output inside a variable and output it where needed if we are afraid of debugging.

Yeah.. Now with basic pattern of https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/scripts/update-report-fixtures.js available, we can much more easily do this in JS. And yeah we can avoid interleaving much easier. 👍

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

once you're feeling good about them, can you also list all the changes to the individual smoke tests. Like yarn smokehouse is getting broken out into an explicit pwa smoke test, a bunch of stuff is getting moved into offline-expectations, but I believe you mentioned that was because you were going to get rid of one of the existing tests that already had a lot of overlap?

package.json Outdated
"smoke": "bash lighthouse-cli/test/smokehouse/run-all-tests.sh",

"smoke": "node lighthouse-cli/test/smokehouse/run-smoke.js",
"coverage": "istanbul cover -x \"**/third_party/**\" _mocha -- $(find */test -name '*-test.js') --reporter progress --report lcovonly",
Copy link
Member

Choose a reason for hiding this comment

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

rebase problem?

const results = runLighthouse(expected.initialUrl, configPath);
console.log(`Comparing results of '${expected.initialUrl}':`);
Copy link
Member

Choose a reason for hiding this comment

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

maybe console.log(`Auditing findings of '${expected.initialUrl}':`);?

Copy link
Collaborator

Choose a reason for hiding this comment

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

😱

config: smokehouseDir + 'pwa-config.js',
},
};

Copy link
Member

Choose a reason for hiding this comment

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

extra line

};


function displayOutput(cp) {
Copy link
Member

Choose a reason for hiding this comment

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

Add jsdoc?

}

/**
* Update the report artifacts
Copy link
Member

Choose a reason for hiding this comment

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

old comment?

serverForOffline.listen(10503, 'localhost');

const cmdPromises = [];
for (const [id, {expectations, config}] of Object.entries(smokes)) {
Copy link
Member

Choose a reason for hiding this comment

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

add way to specify how many to run at the same time? But it sounds like you may be planning that already

@paulirish paulirish changed the title tests(smokehouse): run all run-tests.sh in parallel (WIP) tests(smokehouse): run smoketests in parallel Apr 10, 2018
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 % nits

for (const {id, expectations, config} of smokes) {
// If the machine is terribly slow, do them in succession, not parallel
if (process.env.APPVEYOR) {
await Promise.all(cmdPromises);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd have a slight preference to just move this farther down and await p for clarity

Copy link
Member

Choose a reason for hiding this comment

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

yeah, it's a little confusing at first how this would work since it's Promise.all and at the top of the loop, though it's nice doing it in one line and with the same array as the parallel case :)

const serialSmokeResults = await runSmokehouse(serialSmokes);
smokeResults.push(...serialSmokeResults);

await new Promise(res => server.close(res));
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this really throws me just because res is the canonical express response shorthand and then later you use it for result, resolve or done? :)

await new Promise(res => server.close(res));
await new Promise(res => serverForOffline.close(res));

const failingTests = smokeResults.filter(res => !!res.error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: s/res/anything else :)

const results = runLighthouse(expected.initialUrl, configPath, cli.debug);

console.log(`Auditing findings of '${expected.initialUrl}':`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤦‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

maybe console.log(`Scoring reportCategory results of '${expected.initialUrl}':`); instead?

},
},

// Disabled due to flakiness of site.
Copy link
Member

Choose a reason for hiding this comment

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

should we reenable :)

const results = runLighthouse(expected.initialUrl, configPath, cli.debug);

console.log(`Auditing findings of '${expected.initialUrl}':`);
Copy link
Member

Choose a reason for hiding this comment

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

maybe console.log(`Scoring reportCategory results of '${expected.initialUrl}':`); instead?


/**
* Display smokehouse output from child process
* @param {{id: string, process?: NodeJS.Process, code?: number}} cp
Copy link
Member

Choose a reason for hiding this comment

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

s/cp/result

Copy link
Member

Choose a reason for hiding this comment

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

it would also be something like @param {{id: string, process: NodeJS.Process} || {id: string, error: Error & {stdout : NodeJS.WriteStream, stderr: NodeJS.WriteStream}}} result

but that might be getting a bit silly, especially with no type checking on this file :)

/**
* Run smokehouse in child processes for selected smoketests
* Display output from each as soon as they finish, but resolve function when ALL are complete
* @param {*} smokes
Copy link
Member

Choose a reason for hiding this comment

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

{id: string, expectations: string, config: string}

Copy link
Member

Choose a reason for hiding this comment

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

er, and perfSensitive?: boolean

for (const {id, expectations, config} of smokes) {
// If the machine is terribly slow, do them in succession, not parallel
if (process.env.APPVEYOR) {
await Promise.all(cmdPromises);
Copy link
Member

Choose a reason for hiding this comment

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

yeah, it's a little confusing at first how this would work since it's Promise.all and at the top of the loop, though it's nice doing it in one line and with the same array as the parallel case :)

`--config-path=${config}`,
`--expectations-path=${expectations}`,
].join(' ');
const p = execAsync(cmd, {timeout: 5 * 60 * 1000, encoding: 'utf8'}).then(cp => {
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a comment that the promise then/catch is on purpose so p resolves with process output no matter what?

@@ -23,7 +23,9 @@
"build-viewer": "cd ./lighthouse-viewer && yarn build",
"clean": "rimraf *.report.html *.report.dom.html *.report.json *.screenshots.html *.screenshots.json *.devtoolslog.json *.trace.json || true",
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",
"smoke": "bash lighthouse-cli/test/smokehouse/run-all-tests.sh",

Copy link
Member

Choose a reason for hiding this comment

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

these newlines won't survive a yarn add, fwiw

} else {
smokes = SMOKETESTS.filter(test => argv.includes(test.id));
console.log(`Running ONLY smoketests for: ${smokes.map(t => t.id).join(' ')}\n`);
}
Copy link
Member

Choose a reason for hiding this comment

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

maybe add an error case that prints smokes ids?

}

const parallelSmokes = SMOKETESTS.filter(t => !t.perfSensitive);
const serialSmokes = SMOKETESTS.filter(t => t.perfSensitive);
Copy link
Member

Choose a reason for hiding this comment

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

maybe I'm missing it, but aren't these still run in parallel?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM! 🛤️🛤️🔀🛤️🛤️

/**
*
* @param {string[]} argv
* @return {Map<string, Array<SmoketestDfn>>}
Copy link
Member

Choose a reason for hiding this comment

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

string|undefined? or give a default batch name/symbol so it doesn't fall back to undefined

}

// Split into serial batches that will run their tests concurrently
const batches = smokes.reduce((map, test) => {
Copy link
Member

Choose a reason for hiding this comment

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

is this still running the two perf batches in parallel?

Copy link
Member Author

Choose a reason for hiding this comment

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

currently there's a default batch (with like 7 smoketests) and a perf batch (with 2).

when perf batch goes, the 2 smoketests in there do run in parallel.

I was hoping that style was a little more clear with this "batch" framing.

async function runSmokehouse(smokes) {
const cmdPromises = [];
for (const {id, expectations, config} of smokes) {
console.log(`${purpleify(id)} smoketest starting…`);
Copy link
Member

Choose a reason for hiding this comment

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

for some reason, just for the perf batch, Travis does

screen shot 2018-04-10 at 16 36 19

not sure why :)

const ret = {id: id, error: err};
displaySmokehouseOutput(ret);
return ret;
});
Copy link
Member

@brendankenny brendankenny Apr 10, 2018

Choose a reason for hiding this comment

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

just to code golf, could also be

const p = execAsync(cmd, {timeout: 3 * 60 * 1000, encoding: 'utf8'}).then(cp => {
  return {id: id, process: cp};
}).catch(err => {
  return {id: id, error: err};
}).then(result => displaySmokehouseOutput(result));

(or the even shorter parenthesized version)

@paulirish paulirish merged commit 419b023 into master Apr 11, 2018
@paulirish paulirish deleted the parallelizesmokehouse branch April 11, 2018 01:26
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.

5 participants