From a5e18c4cdfa768021e586982ebf8d307c1081f71 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 27 Jul 2017 08:31:45 +0100 Subject: [PATCH] ci(aio): support sharding of example e2e tests --- aio/tools/examples/run-example-e2e.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/aio/tools/examples/run-example-e2e.js b/aio/tools/examples/run-example-e2e.js index 01fdb651df..369fabd654 100644 --- a/aio/tools/examples/run-example-e2e.js +++ b/aio/tools/examples/run-example-e2e.js @@ -22,8 +22,13 @@ const IGNORED_EXAMPLES = [ * --filter to filter/select _example app subdir names * e.g. --filter=foo // all example apps with 'foo' in their folder names. * - * --setup run yarn install, copy boilerplate and update webdriver + * --setup run yarn install, copy boilerplate and update webdriver * e.g. --setup + * + * --shard to shard the specs into groups to allow you to run them in parallel + * e.g. --shard=0/2 // the even specs: 0, 2, 4, etc + * e.g. --shard=1/2 // the odd specs: 1, 3, 5, etc + * e.g. --shard=1/3 // the second of every three specs: 1, 4, 7, etc */ function runE2e() { let promise = Promise.resolve(); @@ -41,7 +46,7 @@ function runE2e() { const outputFile = path.join(AIO_PATH, './protractor-results.txt'); return promise - .then(() => findAndRunE2eTests(argv.filter, outputFile)) + .then(() => findAndRunE2eTests(argv.filter, outputFile, argv.shard)) .then((status) => { reportStatus(status, outputFile); if (status.failed.length > 0) { @@ -55,7 +60,12 @@ function runE2e() { // Finds all of the *e2e-spec.tests under the examples folder along with the corresponding apps // that they should run under. Then run each app/spec collection sequentially. -function findAndRunE2eTests(filter, outputFile) { +function findAndRunE2eTests(filter, outputFile, shard) { + + const shardParts = shard ? shard.split('/') : [0,1]; + const shardModulo = parseInt(shardParts[0], 10); + const shardDivider = parseInt(shardParts[1], 10); + // create an output file with header. const startTime = new Date().getTime(); let header = `Doc Sample Protractor Results on ${new Date().toLocaleString()}\n`; @@ -65,7 +75,9 @@ function findAndRunE2eTests(filter, outputFile) { // Run the tests sequentially. const status = { passed: [], failed: [] }; return getE2eSpecPaths(EXAMPLES_PATH, filter) - .then(e2eSpecPaths => e2eSpecPaths.reduce((promise, specPath) => { + .then(e2eSpecPaths => e2eSpecPaths + .filter((paths, index) => index % shardDivider === shardModulo) + .reduce((promise, specPath) => { return promise.then(() => { const examplePath = path.dirname(specPath); return runE2eTests(examplePath, outputFile).then((ok) => {