Skip to content

Shard gl jasmine tests #2933

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

Merged
merged 16 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
set +e
set +o pipefail

ROOT=$(dirname $0)/..
EXIT_STATE=0
MAX_AUTO_RETRY=5

Expand All @@ -12,12 +13,14 @@ retry () {
local n=0

until [ $n -ge $MAX_AUTO_RETRY ]; do
if [ $n -ge 1 ]; then
echo ''
echo run $n of $MAX_AUTO_RETRY failed, trying again ...
echo ''
sleep 15
fi
"$@" && break
n=$[$n+1]
echo ''
echo run $n of $MAX_AUTO_RETRY failed, trying again ...
echo ''
sleep 15
done

if [ $n -eq $MAX_AUTO_RETRY ]; then
Expand All @@ -34,7 +37,12 @@ case $1 in
;;

jasmine2)
retry npm run test-jasmine -- --tags=gl --skip-tags=noCI,flaky
SHARDS=($(node $ROOT/tasks/shard_jasmine_tests.js --tag=gl))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

node tasks/shard_jasmine_tests.js --tag=gl outputs:

gl2d_plot_interact_test.js
gl3d_plot_interact_test.js
parcoords_test.js
gl2d_click_test.js
splom_test.js,cartesian_test.js,gl2d_scatterplot_contour_test.js,gl2d_pointcloud_test.js,gl_plot_interact_basic_test.js
streamtube_test.js,gl2d_date_axis_render_test.js,cone_test.js

which is then converted into a bash array (that's the outer ()) and then looped below.


for s in ${SHARDS[@]}; do
retry npm run test-jasmine -- "$s" --tags=gl --skip-tags=noCI
done

retry npm run test-jasmine -- --tags=flaky --skip-tags=noCI
exit $EXIT_STATE
;;
Expand Down
94 changes: 94 additions & 0 deletions tasks/shard_jasmine_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
var fs = require('fs');
var path = require('path');

var falafel = require('falafel');
var glob = require('glob');
var minimist = require('minimist');

var pathToJasmineTests = require('./util/constants').pathToJasmineTests;
var isJasmineTestIt = require('./util/common').isJasmineTestIt;

var argv = minimist(process.argv.slice(2), {
string: ['tag', 'limit'],
alias: {
tag: ['t'],
limit: ['l'],
},
default: {
limit: 20
}
});

var tag = argv.tag;
var limit = argv.limit;

glob(path.join(pathToJasmineTests, '*.js'), function(err, files) {
if(err) throw err;

var file2cnt = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to note, with --limit=20 and --tag=gl, this fills up to:

{ 'cartesian_test.js': 1,
  'cone_test.js': 5,
  'gl_plot_interact_basic_test.js': 2,
  'gl2d_click_test.js': 20,
  'gl2d_date_axis_render_test.js': 4,
  'gl2d_plot_interact_test.js': 28,
  'gl2d_pointcloud_test.js': 2,
  'gl2d_scatterplot_contour_test.js': 2,
  'gl3d_plot_interact_test.js': 26,
  'parcoords_test.js': 30,
  'splom_test.js': 10,
  'streamtube_test.js': 10 }


files.forEach(function(file) {
var code = fs.readFileSync(file, 'utf-8');
var bn = path.basename(file);

falafel(code, function(node) {
if(isJasmineTestIt(node, tag)) {
if(file2cnt[bn]) {
file2cnt[bn]++;
} else {
file2cnt[bn] = 1;
}
}
});
});

var ranking = Object.keys(file2cnt);
var runs = [];

// if 'it' count in file greater than threshold,
// run only this file separately,
// don't try to shard within file
Object.keys(file2cnt).forEach(function(f) {
if(file2cnt[f] > limit) {
runs.push(f);
ranking.splice(ranking.indexOf(f), 1);
}
});

// sort ranking in decreasing order
ranking.sort(function(a, b) { return file2cnt[b] - file2cnt[a]; });

var runi;
var cnt;

function newRun() {
var r0 = ranking[0];
runi = [r0];
cnt = file2cnt[r0];
ranking.shift();
}

function concat() {
runs.push(runi.join(','));
}

// try to match files with many tests with files not-that-many,
// by matching first rank with one or multiple trailing ranks.
newRun();
while(ranking.length) {
var rn = ranking[ranking.length - 1];

if((cnt + file2cnt[rn]) > limit) {
concat();
newRun();
} else {
runi.push(rn);
cnt += file2cnt[rn];
ranking.pop();
}
}
concat();

// print result to stdout
console.log(runs.join('\n'));
});
47 changes: 43 additions & 4 deletions tasks/test_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ var readLastLines = require('read-last-lines');
var eslint = require('eslint');
var trueCasePath = require('true-case-path');

var common = require('./util/common');
var isJasmineTestIt = common.isJasmineTestIt;
var isJasmineTestDescribe = common.isJasmineTestDescribe;
var hasJasmineTestTag = common.hasJasmineTestTag;

var constants = require('./util/constants');
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
var libGlob = path.join(constants.pathToLib, '**/*.js');
Expand All @@ -28,26 +33,60 @@ assertES5();
// check for for focus and exclude jasmine blocks
function assertJasmineSuites() {
var BLACK_LIST = ['fdescribe', 'fit', 'xdescribe', 'xit'];
var TAGS = ['noCI', 'noCIdep', 'gl', 'flaky'];
var IT_ONLY_TAGS = ['gl', 'flaky'];
var logs = [];

var addTagPrefix = function(t) { return '@' + t; };

glob(combineGlobs([testGlob, bundleTestGlob]), function(err, files) {
files.forEach(function(file) {
var code = fs.readFileSync(file, 'utf-8');
var bn = path.basename(file);

falafel(code, {locations: true}, function(node) {
var lineInfo = '[line ' + node.loc.start.line + '] :';

if(node.type === 'Identifier' && BLACK_LIST.indexOf(node.name) !== -1) {
logs.push([
path.basename(file),
'[line ' + node.loc.start.line + '] :',
bn, lineInfo,
'contains either a *fdescribe*, *fit*,',
'*xdescribe* or *xit* block.'
].join(' '));
}
});

if(isJasmineTestIt(node)) {
if(hasJasmineTestTag(node)) {
if(TAGS.every(function(t) { return !hasJasmineTestTag(node, t); })) {
logs.push([
bn, lineInfo,
'contains an unrecognized tag,',
'not one of: ' + TAGS.map(addTagPrefix).join(', ')
].join(' '));
}
}

if(hasJasmineTestTag(node, 'gl') && hasJasmineTestTag(node, 'flaky')) {
logs.push([
bn, lineInfo,
'contains a @gl tag AND a @flaky tag, which is not allowed'
].join(' '));
}
}

IT_ONLY_TAGS.forEach(function(t) {
if(isJasmineTestDescribe(node, t)) {
logs.push([
bn, lineInfo,
'contains a', addTagPrefix(t), 'tag is a *describe* block,',
addTagPrefix(t), 'tags are only allowed in jasmine *it* blocks.'
].join(' '));
}
});
});
});

log('no jasmine suites focus/exclude blocks', logs);
log('no jasmine suites focus/exclude blocks or wrong tag patterns', logs);
});
}

Expand Down
27 changes: 27 additions & 0 deletions tasks/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,30 @@ exports.formatEnumeration = function(list) {
return '`' + l + '`' + ending;
}).join(' ');
};

exports.hasJasmineTestTag = function(node, tag) {
var re = tag ?
new RegExp('@' + tag + '\\s') :
new RegExp('@' + '\\w');
return re.test(node.source());
};

function isJasmineBase(block, node, tag) {
return (
node.type === 'Literal' &&
node.parent &&
node.parent.type === 'CallExpression' &&
node.parent.callee &&
node.parent.callee.type === 'Identifier' &&
node.parent.callee.name === block &&
(tag === undefined || exports.hasJasmineTestTag(node, tag))
);
}

exports.isJasmineTestIt = function(node, tag) {
return isJasmineBase('it', node, tag);
};

exports.isJasmineTestDescribe = function(node, tag) {
return isJasmineBase('describe', node, tag);
};
5 changes: 4 additions & 1 deletion test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ func.defaultConfig = {
suppressSkipped: false,
showSpecTiming: false,
failFast: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this failFast shouldn't ever be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting it to true won't break anything, but it won't actually fail fast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More on this topic: to make karma-spec-reporter fail fast, one needs to add it to the plugins list: https://github.com/mlex/karma-spec-reporter#configuration

When doing so, it conflicts with karma-browserify.

There might be a way, to list them (order dependent?) so that they don't conflict, but using karma-fail-fast-reporter was easy enough.

}
},

// e.g. when a test file does not container a given spec tags
failOnEmptyTestSuite: false
};

func.defaultConfig.preprocessors[pathToCustomMatchers] = ['browserify'];
Expand Down
14 changes: 7 additions & 7 deletions test/jasmine/tests/cone_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Test cone defaults', function() {
});
});

describe('@gl Test cone autorange:', function() {
describe('Test cone autorange:', function() {
var gd;

beforeEach(function() {
Expand All @@ -79,7 +79,7 @@ describe('@gl Test cone autorange:', function() {
expect(sceneLayout.zaxis.range).toBeCloseToArray(zrng, 2, 'zaxis range - ' + msg);
}

it('should add pad around cone position to make sure they fit on the scene', function(done) {
it('@gl should add pad around cone position to make sure they fit on the scene', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-autorange.json'));
var rng0 = [0.103, 3.897];

Expand Down Expand Up @@ -177,7 +177,7 @@ describe('@gl Test cone autorange:', function() {
});
});

describe('@gl Test cone interactions', function() {
describe('Test cone interactions', function() {
var gd;

beforeEach(function() {
Expand All @@ -189,7 +189,7 @@ describe('@gl Test cone interactions', function() {
destroyGraphDiv();
});

it('should add/clear gl objects correctly', function(done) {
it('@gl should add/clear gl objects correctly', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-simple.json'));
// put traces on same subplot
delete fig.data[1].scene;
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('@gl Test cone interactions', function() {
.then(done);
});

it('should not pass zero or infinite `coneSize` to gl-cone3d', function(done) {
it('@gl should not pass zero or infinite `coneSize` to gl-cone3d', function(done) {
var base = {
type: 'cone',
x: [1, 2, 3],
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('@gl Test cone interactions', function() {
.then(done);
});

it('should display hover labels', function(done) {
it('@gl should display hover labels', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-simple.json'));
// only one trace on one scene
fig.data = [fig.data[0]];
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('@gl Test cone interactions', function() {
.then(done);
});

it('should display hover labels (multi-trace case)', function(done) {
it('@gl should display hover labels (multi-trace case)', function(done) {
function _hover() {
mouseEvent('mouseover', 282, 240);
return delay(20)();
Expand Down
Loading