Skip to content

Commit 440a9d1

Browse files
committed
ci: add sharding for e2e tests
1 parent fd52246 commit 440a9d1

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

.travis.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ matrix:
4040
env: test
4141
- node_js: "6"
4242
os: linux
43-
script: node tests/run_e2e.js "--glob=tests/build/**"
44-
env: build
43+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=0
44+
env: e2e-0
45+
- node_js: "6"
46+
os: linux
47+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=1
48+
env: e2e-1
49+
- node_js: "6"
50+
os: linux
51+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=2
52+
env: e2e-2
4553
- node_js: "6"
4654
os: linux
47-
script: travis_wait 120 node tests/run_e2e.js "--ignore=**/tests/build/**"
48-
env: e2e
55+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=3
56+
env: e2e-3
4957
- node_js: "6"
5058
os: linux
5159
script: node tests/run_e2e.js --eject "--glob=tests/build/**"

tests/e2e_runner.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ Error.stackTraceLimit = Infinity;
3636
* --reuse=/path Use a path instead of create a new project. That project should have been
3737
* created, and npm installed. Ideally you want a project created by a previous
3838
* run of e2e.
39+
* --nb-shards Total number of shards that this is part of. Default is 2 if --shard is
40+
* passed in.
41+
* --shard Index of this processes' shard.
3942
* If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
4043
*/
4144
const argv = minimist(process.argv.slice(2), {
4245
'boolean': ['debug', 'nolink', 'nightly', 'noproject', 'verbose', 'eject', 'appveyor'],
43-
'string': ['glob', 'ignore', 'reuse', 'ng-sha', ]
46+
'string': ['glob', 'ignore', 'reuse', 'ng-sha', ],
47+
'number': ['nb-shards', 'shard']
4448
});
4549

4650

@@ -73,7 +77,6 @@ ConsoleLoggerStack.start(new IndentLogger('name'))
7377

7478
const testGlob = argv.glob || 'tests/**/*.ts';
7579
let currentFileName = null;
76-
let index = 0;
7780

7881
const e2eRoot = path.join(__dirname, 'e2e');
7982
const allSetups = glob.sync(path.join(e2eRoot, 'setup/**/*.ts'), { nodir: true })
@@ -83,20 +86,26 @@ const allTests = glob.sync(path.join(e2eRoot, testGlob), { nodir: true, ignore:
8386
.map(name => path.relative(e2eRoot, name))
8487
.sort();
8588

86-
const testsToRun = allSetups
87-
.concat(allTests
88-
.filter(name => {
89-
// Check for naming tests on command line.
90-
if (argv._.length == 0) {
91-
return true;
92-
}
89+
const shardId = ('shard' in argv) ? argv['shard'] : null;
90+
const nbShards = (shardId === null ? 1 : argv['nb-shards']) || 2;
91+
const tests = allTests
92+
.filter(name => {
93+
// Check for naming tests on command line.
94+
if (argv._.length == 0) {
95+
return true;
96+
}
97+
98+
return argv._.some(argName => {
99+
return path.join(process.cwd(), argName) == path.join(__dirname, 'e2e', name)
100+
|| argName == name
101+
|| argName == name.replace(/\.ts$/, '');
102+
});
103+
});
93104

94-
return argv._.some(argName => {
95-
return path.join(process.cwd(), argName) == path.join(__dirname, 'e2e', name)
96-
|| argName == name
97-
|| argName == name.replace(/\.ts$/, '');
98-
});
99-
}));
105+
// Remove tests that are not part of this shard.
106+
const shardedTests = tests
107+
.filter((name, i) => (shardId === null || (i % nbShards) == shardId));
108+
const testsToRun = allSetups.concat(shardedTests);
100109

101110

102111
/**
@@ -111,7 +120,7 @@ if (testsToRun.length == allTests.length) {
111120

112121
setGlobalVariable('argv', argv);
113122

114-
testsToRun.reduce((previous, relativeName) => {
123+
testsToRun.reduce((previous, relativeName, testIndex) => {
115124
// Make sure this is a windows compatible path.
116125
let absoluteName = path.join(e2eRoot, relativeName);
117126
if (/^win/.test(process.platform)) {
@@ -131,7 +140,7 @@ testsToRun.reduce((previous, relativeName) => {
131140
let clean = true;
132141
let previousDir = null;
133142
return Promise.resolve()
134-
.then(() => printHeader(currentFileName))
143+
.then(() => printHeader(currentFileName, testIndex))
135144
.then(() => previousDir = process.cwd())
136145
.then(() => ConsoleLoggerStack.push(currentFileName))
137146
.then(() => fn(() => clean = false))
@@ -196,9 +205,14 @@ function isTravis() {
196205
return process.env['TRAVIS'];
197206
}
198207

199-
function printHeader(testName) {
200-
const text = `${++index} of ${testsToRun.length}`;
201-
console.log(green(`Running "${bold(blue(testName))}" (${bold(white(text))})...`));
208+
function printHeader(testName: string, testIndex: number) {
209+
const text = `${testIndex + 1} of ${testsToRun.length}`;
210+
const fullIndex = (testIndex < allSetups.length ? testIndex
211+
: (testIndex - allSetups.length) * nbShards + shardId + allSetups.length) + 1;
212+
const length = tests.length + allSetups.length;
213+
const shard = shardId === null ? ''
214+
: yellow(` [${shardId}:${nbShards}]` + bold(` (${fullIndex}/${length})`));
215+
console.log(green(`Running "${bold(blue(testName))}" (${bold(white(text))}${shard})...`));
202216

203217
if (isTravis()) {
204218
console.log(`travis_fold:start:${encode(testName)}`);

0 commit comments

Comments
 (0)