Skip to content

Commit

Permalink
add coverage for BufferedWorkerPool.terminate()
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed May 27, 2020
1 parent 5df8f53 commit 986f412
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/nodejs/buffered-worker-pool.js
Expand Up @@ -10,7 +10,7 @@
const serializeJavascript = require('serialize-javascript');
const workerpool = require('workerpool');
const {deserialize} = require('./serializer');
const debug = require('debug')('mocha:parallel:pool');
const debug = require('debug')('mocha:parallel:buffered-worker-pool');
const {cpus} = require('os');
const {createInvalidArgumentTypeError} = require('../errors');

Expand Down Expand Up @@ -61,17 +61,20 @@ class BufferedWorkerPool {
const maxWorkers = Math.max(1, opts.maxWorkers);

if (maxWorkers < 2) {
/* istanbul ignore next */
debug(
'not enough CPU cores available (%d) to run multiple jobs; avoid --parallel on this machine',
CPU_COUNT
);
} else if (maxWorkers >= CPU_COUNT) {
/* istanbul ignore next */
debug(
'%d concurrent job(s) requested, but only %d core(s) available',
maxWorkers,
CPU_COUNT
);
}
/* istanbul ignore next */
debug(
'run(): starting worker pool of max size %d, using node args: %s',
maxWorkers,
Expand All @@ -89,6 +92,8 @@ class BufferedWorkerPool {
* @returns {Promise<void>}
*/
async terminate(force = false) {
/* istanbul ignore next */
debug('terminate(): terminating with force = %s', force);
return this._pool.terminate(force);
}

Expand Down Expand Up @@ -128,6 +133,7 @@ class BufferedWorkerPool {

/**
* Instantiates a {@link WorkerPool}.
* @private
*/
static create(...args) {
return new BufferedWorkerPool(...args);
Expand All @@ -148,6 +154,7 @@ class BufferedWorkerPool {
ignoreFunction: true // do not serialize functions
});
optionsCache.set(opts, serialized);
/* istanbul ignore next */
debug(
'serializeOptions(): serialized options %O to: %s',
opts,
Expand Down
26 changes: 26 additions & 0 deletions test/node-unit/buffered-worker-pool.spec.js
Expand Up @@ -155,5 +155,31 @@ describe('class BufferedWorkerPool', function() {
]).and('was called once');
});
});

describe('terminate()', function() {
describe('when called with `force`', function() {
beforeEach(async function() {
await workerPool.terminate(true);
});

it('should delegate to the underlying pool w/ "force" behavior', async function() {
expect(pool.terminate, 'to have a call satisfying', [true]).and(
'was called once'
);
});
});

describe('when called without `force`', function() {
beforeEach(async function() {
await workerPool.terminate();
});

it('should delegate to the underlying pool w/o "force" behavior', async function() {
expect(pool.terminate, 'to have a call satisfying', [false]).and(
'was called once'
);
});
});
});
});
});

0 comments on commit 986f412

Please sign in to comment.