8000 feat(config): add support for workers config option · gemini-testing/gemini@d7b7710 · 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.

Commit d7b7710

Browse files
author
Alexander Kukhta
committed
feat(config): add support for workers config option
Allows to limit maximum amount of workers run in parallel during testing. Should help running tests on servers with a lot of cpu cores (i.e. CI agent), as worker-farm (that is used for managing workers) use os.cpus().length as a default value
1 parent a5e8aef commit d7b7710

9 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎doc/config.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ system:
6565
teamcity: true
6666
debug: true
6767
parallelLimit: 3
68+
workers: 4
6869
diffColor: '#ff0000'
6970
coverage:
7071
enabled: true
@@ -125,6 +126,9 @@ exclude:
125126
option to limit the number of browsers that `gemini` will try to run in
126127
parallel.
127128

129+
* `workers` — by default, `gemini` will run as many parallel
130+
workers as cores available, this option allows you to limit it.
131+
128132
* `diffColor` — specifies color which will be used to highlight differences
129133
between images. Specified in hexadecimal RGB (`#RRGGBB`). Magenta by default
130134
(`#FF00FF`).

‎lib/config/options.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const os = require('os');
34
const path = require('path');
45
const configparser = require('gemini-configparser');
56
const _ = require('lodash');
@@ -45,6 +46,8 @@ module.exports = root(
4546

4647
parallelLimit: positiveIntegerOption(Infinity),
4748

49+
workers: positiveIntegerOption(os.cpus().length),
50+
4851
diffColor: option({
4952
defaultValue: '#ff00ff',
5053
validate: (value) => {

‎lib/gemini.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = class Gemini extends PassthroughEmitter {
8282
}
8383

8484
update(paths, options) {
85-
return this._exec(() => this._run(StateProcessor.createScreenUpdater(options), paths, options));
85+
return this._exec(() => this._run(StateProcessor.createScreenUpdater(this.config, options), paths, options));
8686
}
8787

8888
test(paths, options) {

‎lib/state-processor/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
return new TestStateProcessor(config);
99
},
1010

11-
createScreenUpdater: function(options) {
12-
return new UpdateStateProcessor(options);
11+
createScreenUpdater: function(config, options) {
12+
return new UpdateStateProcessor(config, options);
1313
}
1414
};

‎lib/state-processor/state-processor.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ const Events = require('../constants/events');
99
const errorUtils = require('../errors/utils');
1010

1111
module.exports = class StateProcessor {
12-
constructor(captureProcessorType) {
12+
constructor(captureProcessorType, maxConcurrentWorkers) {
1313
this._captureProcessorType = captureProcessorType;
14+
this._maxConcurrentWorkers = maxConcurrentWorkers;
1415
}
1516

1617
prepare(emitter) {
17-
this._workers = workerFarm(require.resolve('./job'));
18+
const workerFarmConfig = {
19+
maxConcurrentWorkers: this._maxConcurrentWorkers
20+
};
21+
this._workers = workerFarm(workerFarmConfig, require.resolve('./job'));
1822
emitter.on(Events.END, () => workerFarm.end(this._workers));
1923
}
2024

‎lib/state-processor/test-state-processor.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {Image} = require('gemini-core');
88

99
module.exports = class TestStateProcessor extends StateProcessor {
1010
constructor(config) {
11-
super('tester');
11+
super('tester', config.system.workers);
1212

1313
this._diffColor = config.system.diffColor;
1414
}

‎lib/state-processor/update-state-processor.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const StateProcessor = require('./state-processor');
44
const Events = require('../constants/events');
55

66
module.exports = class UpdateStateProcessor extends StateProcessor {
7-
constructor(opts) {
7+
constructor(config, opts) {
88
const updaterType = opts.diff && !opts.new && 'diff-updater'
99
|| !opts.diff && opts.new && 'new-updater'
1010
|| 'meta-updater';
1111

12-
super(updaterType);
12+
super(updaterType, config.system.workers);
1313
}
1414

1515
exec(state, browserSession, page, emit) {

‎test/unit/state-processor/state-processor.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('state-processor/state-processor', () => {
3838
return (args, cb) => cb(null, job(args));
3939
}
4040
});
41-
const stateProcessor = new StateProcessor(opts.captureProcessorType);
41+
const stateProcessor = new StateProcessor(opts.captureProcessorType, 4);
4242

4343
stateProcessor.prepare(new AsyncEmitter());
4444
return stateProcessor.exec(opts.state, browserSession, opts.page);

‎test/unit/state-processor/update-state-processor.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const util = require('../../util');
1010

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

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

22-
return new UpdateStateProcessor({}).exec(opts.state, opts.browserSession, opts.page, opts.emit);
23+
return new UpdateStateProcessor(config, {}).exec(opts.state, opts.browserSession, opts.page, opts.emit);
2324
};
2425

2526
beforeEach(() => sandbox.stub(StateProcessor.prototype, 'exec'));

0 commit comments

Comments
 (0)
0