8000 feat(config): add support for parallelWorkersLimit config option by thers · Pull Request #970 · gemini-testing/gemini · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
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: 4 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ system:
teamcity: true
debug: true
parallelLimit: 3
workers: 4
diffColor: '#ff0000'
coverage:
enabled: true
Expand Down Expand Up @@ -125,6 +126,9 @@ exclude:
option to limit the number of browsers that `gemini` will try to run in
parallel.

* `workers` — by default, `gemini` will run as many parallel
workers as cores available, this option allows you to limit it.

* `diffColor` — specifies color which will be used to highlight differences
between images. Specified in hexadecimal RGB (`#RRGGBB`). Magenta by default
(`#FF00FF`).
Expand Down
3 changes: 3 additions & 0 deletions lib/config/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const os = require('os');
const path = require('path');
const configparser = require('gemini-configparser');
const _ = require('lodash');
Expand Down Expand Up @@ -45,6 +46,8 @@ module.exports = root(

parallelLimit: positiveIntegerOption(Infinity),

workers: positiveIntegerOption(os.cpus().length),

diffColor: option({
defaultValue: '#ff00ff',
validate: (value) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = class Gemini extends PassthroughEmitter {
}

update(paths, options) {
return this._exec(() => this._run(StateProcessor.createScreenUpdater(options), paths, options));
return this._exec(() => this._run(StateProcessor.createScreenUpdater(this.config, options), paths, options));
}

test(paths, options) {
Expand Down
4 changes: 2 additions & 2 deletions lib/state-processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
return new TestStateProcessor(config);
},

createScreenUpdater: function(options) {
return new UpdateStateProcessor(options);
createScreenUpdater: function(config, options) {
return new UpdateStateProcessor(config, options);
}
};
8 changes: 6 additions & 2 deletions lib/state-processor/state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ const Events = require('../constants/events');
const errorUtils = require('../errors/utils');

module.exports = class StateProcessor {
constructor(captureProcessorType) {
constructor(captureProcessorType, maxConcurrentWorkers) {
this._captureProcessorType = captureProcessorType;
this._maxConcurrentWorkers = maxConcurrentWorkers;
}

prepare(emitter) {
this._workers = workerFarm(require.resolve('./job'));
const workerFarmConfig = {
maxConcurrentWorkers: this._maxConcurrentWorkers
};
this._workers = workerFarm(workerFarmConfig, require.resolve('./job'));
emitter.on(Events.END, () => workerFarm.end(this._workers));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/state-processor/test-state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {Image} = require('gemini-core');

module.exports = class TestStateProcessor extends StateProcessor {
constructor(config) {
super('tester');
super('tester', config.system.workers);

this._diffColor = config.system.diffColor;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/state-processor/update-state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const StateProcessor = require('./state-processor');
const Events = require('../constants/events');

module.exports = class UpdateStateProcessor extends StateProcessor {
constructor(opts) {
constructor(config, opts) {
const updaterType = opts.diff && !opts.new && 'diff-updater'
|| !opts.diff && opts.new && 'new-updater'
|| 'meta-updater';

super(updaterType);
super(updaterType, config.system.workers);
}

exec(state, browserSession, page, emit) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/state-processor/state-processor.js
8
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('state-processor/state-processor', () => {
return (args, cb) => cb(null, job(args));
}
});
const stateProcessor = new StateProcessor(opts.captureProcessorType);
const stateProcessor = new StateProcessor(opts.captureProcessorType, 4);

stateProcessor.prepare(new AsyncEmitter());
return stateProcessor.exec(opts.state, browserSession, opts.page);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/state-processor/update-state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const util = require('../../util');

describe('state-processor/update-state-processor', () => {
const sandbox = sinon.sandbox.create();
const config = {system: {workers: 4}};

const exec_ = (opts) => {
opts = _.defaultsDeep(opts || {}, {
Expand All @@ -19,7 +20,7 @@ describe('state-processor/update-state-processor', () => {
emit: sinon.spy()
});

return new UpdateStateProcessor({}).exec(opts.state, opts.browserSession, opts.page, opts.emit);
return new UpdateStateProcessor(config, {}).exec(opts.state, opts.browserSession, opts.page, opts.emit);
};

beforeEach(() => sandbox.stub(StateProcessor.prototype, 'exec'));
Expand Down
0