Skip to content

Commit 9067839

Browse files
committed
Merge pull request #468 from n-riesco/image-test-throttle
Throttle the image tests run concurrently
2 parents b0e7756 + c0e6aaf commit 9067839

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

test/image/compare_pixels_test.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var gm = require('gm');
1212
var TOLERANCE = 1e-6; // pixel comparison tolerance
1313
var BASE_TIMEOUT = 500; // base timeout time
1414
var BATCH_SIZE = 5; // size of each test 'batch'
15+
var running = 0; // number of tests currently running
1516

1617
var touch = function(fileName) {
1718
fs.closeSync(fs.openSync(fileName, 'w'));
@@ -53,17 +54,10 @@ function runAll() {
5354
);
5455
});
5556

56-
var cnt = 0;
57-
58-
function testFunction() {
59-
testMock(mocks[cnt++], t);
60-
}
61-
6257
t.plan(mocks.length);
6358

6459
for(var i = 0; i < mocks.length; i++) {
65-
setTimeout(testFunction,
66-
BASE_TIMEOUT * Math.floor(i / BATCH_SIZE) * BATCH_SIZE);
60+
testMock(mocks[i], t);
6761
}
6862

6963
});
@@ -77,6 +71,13 @@ function runSingle(userFileName) {
7771
}
7872

7973
function testMock(fileName, t) {
74+
// throttle the number of tests running concurrently
75+
if(running >= BATCH_SIZE) {
76+
setTimeout(function() { testMock(fileName, t); }, BASE_TIMEOUT);
77+
return;
78+
}
79+
running++;
80+
8081
var figure = require(path.join(constants.pathToTestImageMocks, fileName));
8182
var bodyMock = {
8283
figure: figure,
@@ -91,6 +92,8 @@ function testMock(fileName, t) {
9192
var options = getOptions(bodyMock, 'http://localhost:9010/');
9293

9394
function checkImage() {
95+
running--;
96+
9497
var options = {
9598
file: diffPath,
9699
highlightColor: 'purple',

0 commit comments

Comments
 (0)