Skip to content

Commit ca4ab42

Browse files
authored
Merge pull request #1490 from plotly/batch-export-tests
Batch image export tests
2 parents d9f6c1b + 32b9696 commit ca4ab42

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

tasks/ci_test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ case $CIRCLE_NODE_INDEX in
77
0)
88
npm run test-image || EXIT_STATE=$?
99
npm run test-image-gl2d || EXIT_STATE=$?
10-
npm run test-export || EXIT_STATE=$?
10+
npm run test-bundle || EXIT_STATE=$?
1111
npm run test-syntax || EXIT_STATE=$?
1212
npm run lint || EXIT_STATE=$?
1313
exit $EXIT_STATE
1414
;;
1515

1616
1)
1717
npm run test-jasmine || EXIT_STATE=$?
18-
npm run test-bundle || EXIT_STATE=$?
18+
npm run test-export || EXIT_STATE=$?
1919
exit $EXIT_STATE
2020
;;
2121

test/image/export_test.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ var HEIGHT = 500;
3030
// minimum satisfactory file size [in bytes]
3131
var MIN_SIZE = 100;
3232

33+
// wait time between each test batch
34+
var BATCH_WAIT = 500;
35+
36+
// number of tests in each test batch
37+
var BATCH_SIZE = 5;
38+
3339
/**
3440
* Image export test script.
3541
*
@@ -65,21 +71,39 @@ if(mockList.length === 0) {
6571
runInBatch(mockList);
6672

6773
function runInBatch(mockList) {
74+
var running = 0;
75+
6876
test('testing image export formats', function(t) {
6977
t.plan(mockList.length * FORMATS.length);
7078

71-
// send all requests out at once
72-
mockList.forEach(function(mockName) {
73-
FORMATS.forEach(function(format) {
74-
testExport(mockName, format, t);
75-
});
76-
});
79+
for(var i = 0; i < mockList.length; i++) {
80+
for(var j = 0; j < FORMATS.length; j++) {
81+
run(mockList[i], FORMATS[j], t);
82+
}
83+
}
7784
});
85+
86+
function run(mockName, format, t) {
87+
if(running >= BATCH_SIZE) {
88+
setTimeout(function() {
89+
run(mockName, format, t);
90+
}, BATCH_WAIT);
91+
return;
92+
}
93+
running++;
94+
95+
// throttle the number of tests running concurrently
96+
97+
testExport(mockName, format, function(didExport, mockName, format) {
98+
running--;
99+
t.ok(didExport, mockName + ' should be properly exported as a ' + format);
100+
});
101+
}
78102
}
79103

80104
// The tests below determine whether the images are properly
81105
// exported by (only) checking the file size of the generated images.
82-
function testExport(mockName, format, t) {
106+
function testExport(mockName, format, cb) {
83107
var specs = {
84108
mockName: mockName,
85109
format: format,
@@ -105,7 +129,7 @@ function testExport(mockName, format, t) {
105129
didExport = stats.size > MIN_SIZE;
106130
}
107131

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

111135
request(requestOpts)

0 commit comments

Comments
 (0)