Skip to content
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

Execute each images comparison in a separate child processes (#561) #571

Merged
merged 2 commits into from
Oct 20, 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
29 changes: 26 additions & 3 deletions core/util/compare/compare.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
var compareHashes = require('./compare-hash');
var compareResemble = require('./compare-resemble');
var storeFailedDiff = require('./store-failed-diff.js');

module.exports = function (referencePath, testPath, misMatchThreshold, resembleOutputSettings, requireSameDimensions) {
return compareHashes(referencePath, testPath)
.catch(() => compareResemble(referencePath, testPath, misMatchThreshold, resembleOutputSettings, requireSameDimensions));
process.on('message', compare);

function compare (data) {
var {referencePath, testPath, resembleOutputSettings, pair} = data;
var promise = compareHashes(referencePath, testPath)
.catch(() => compareResemble(referencePath, testPath, pair.misMatchThreshold, resembleOutputSettings, pair.requireSameDimensions));
promise
.then(function (data) {
pair.diff = data;
pair.status = 'pass';
return sendMessage(pair);
})
.catch(function (data) {
pair.diff = data;
pair.status = 'fail';

return storeFailedDiff(testPath, data).then(function (compare) {
pair.diffImage = compare;
return sendMessage(pair);
});
});
};

function sendMessage (data) {
process.send(data);
}
44 changes: 23 additions & 21 deletions core/util/compare/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var path = require('path');
var map = require('p-map');
var fs = require('fs');
var cp = require('child_process');

var compare = require('./compare');
var Reporter = require('./../Reporter');
var logger = require('./../logger')('compare');
var storeFailedDiff = require('./store-failed-diff.js');
var storeFailedDiffStub = require('./store-failed-diff-stub.js');

var ASYNC_COMPARE_LIMIT = 20;
Expand Down Expand Up @@ -48,27 +47,30 @@ function comparePair (pair, report, config) {
}

function compareImages (referencePath, testPath, pair, resembleOutputSettings, Test) {
return compare(referencePath, testPath, pair.misMatchThreshold, resembleOutputSettings, pair.requireSameDimensions)
.then(function (data) {
pair.diff = data;
Test.status = 'pass';
logger.success('OK: ' + pair.label + ' ' + pair.fileName);
data = null;
pair.diff.getDiffImage = null;
return pair;
})
.catch(function (data) {
pair.diff = data;
Test.status = 'fail';
logger.error('ERROR { requireSameDimensions: ' + (data.requireSameDimensions ? 'true' : 'false') + ' size: ' + (data.isSameDimensions ? 'ok' : 'isDifferent') + ', content: ' + data.misMatchPercentage + '%, threshold: ' + pair.misMatchThreshold + '% }: ' + pair.label + ' ' + pair.fileName);
return new Promise(function (resolve, reject) {
var worker = cp.fork(require.resolve('./compare'));
worker.send({
referencePath : referencePath,
testPath : testPath,
resembleOutputSettings : resembleOutputSettings,
pair : pair
});

worker.on('message', function (data) {
worker.kill();
Test.status = data.status;
pair.diff = data.diff;

if (data.status == 'fail') {
pair.diffImage = data.diffImage;
logger.error('ERROR { requireSameDimensions: ' + (data.requireSameDimensions ? 'true' : 'false') + ', size: ' + (data.isSameDimensions ? 'ok' : 'isDifferent') + ', content: ' + data.misMatchPercentage + '%, threshold: ' + pair.misMatchThreshold + '% }: ' + pair.label + ' ' + pair.fileName);
} else {
logger.success('OK: ' + pair.label + ' ' + pair.fileName);
}

return storeFailedDiff(testPath, data).then(function (compare) {
pair.diffImage = compare;
data = null;
pair.diff.getDiffImage = null;
return pair;
});
resolve(data);
});
});
}

module.exports = function (config) {
Expand Down