Skip to content

Batch image export tests #1490

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 2 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions tasks/ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ case $CIRCLE_NODE_INDEX in
0)
npm run test-image || EXIT_STATE=$?
npm run test-image-gl2d || EXIT_STATE=$?
npm run test-export || EXIT_STATE=$?
npm run test-bundle || EXIT_STATE=$?
npm run test-syntax || EXIT_STATE=$?
npm run lint || EXIT_STATE=$?
exit $EXIT_STATE
;;

1)
npm run test-jasmine || EXIT_STATE=$?
npm run test-bundle || EXIT_STATE=$?
npm run test-export || EXIT_STATE=$?
exit $EXIT_STATE
;;

Expand Down
40 changes: 32 additions & 8 deletions test/image/export_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ var HEIGHT = 500;
// minimum satisfactory file size [in bytes]
var MIN_SIZE = 100;

// wait time between each test batch
var BATCH_WAIT = 500;

// number of tests in each test batch
var BATCH_SIZE = 5;

/**
* Image export test script.
*
Expand Down Expand Up @@ -65,21 +71,39 @@ if(mockList.length === 0) {
runInBatch(mockList);

function runInBatch(mockList) {
var running = 0;

test('testing image export formats', function(t) {
t.plan(mockList.length * FORMATS.length);

// send all requests out at once
mockList.forEach(function(mockName) {
FORMATS.forEach(function(format) {
testExport(mockName, format, t);
});
});
for(var i = 0; i < mockList.length; i++) {
for(var j = 0; j < FORMATS.length; j++) {
run(mockList[i], FORMATS[j], t);
}
}
});

function run(mockName, format, t) {
if(running >= BATCH_SIZE) {
setTimeout(function() {
run(mockName, format, t);
}, BATCH_WAIT);
return;
}
running++;

// throttle the number of tests running concurrently

testExport(mockName, format, function(didExport, mockName, format) {
running--;
t.ok(didExport, mockName + ' should be properly exported as a ' + format);
});
}
}

// The tests below determine whether the images are properly
// exported by (only) checking the file size of the generated images.
function testExport(mockName, format, t) {
function testExport(mockName, format, cb) {
var specs = {
mockName: mockName,
format: format,
Expand All @@ -105,7 +129,7 @@ function testExport(mockName, format, t) {
didExport = stats.size > MIN_SIZE;
}

t.ok(didExport, mockName + ' should be properly exported as a ' + format);
cb(didExport, mockName, format);
}

request(requestOpts)
Expand Down