From 986f412b62369a8f077c4d176eb35d147864eadf Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 27 May 2020 11:04:22 -0700 Subject: [PATCH] add coverage for BufferedWorkerPool.terminate() Signed-off-by: Christopher Hiller --- lib/nodejs/buffered-worker-pool.js | 9 ++++++- test/node-unit/buffered-worker-pool.spec.js | 26 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/nodejs/buffered-worker-pool.js b/lib/nodejs/buffered-worker-pool.js index 894f855446..0d1a03b168 100644 --- a/lib/nodejs/buffered-worker-pool.js +++ b/lib/nodejs/buffered-worker-pool.js @@ -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'); @@ -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, @@ -89,6 +92,8 @@ class BufferedWorkerPool { * @returns {Promise} */ async terminate(force = false) { + /* istanbul ignore next */ + debug('terminate(): terminating with force = %s', force); return this._pool.terminate(force); } @@ -128,6 +133,7 @@ class BufferedWorkerPool { /** * Instantiates a {@link WorkerPool}. + * @private */ static create(...args) { return new BufferedWorkerPool(...args); @@ -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, diff --git a/test/node-unit/buffered-worker-pool.spec.js b/test/node-unit/buffered-worker-pool.spec.js index 1aa5ed6547..0d2ab4e7c9 100644 --- a/test/node-unit/buffered-worker-pool.spec.js +++ b/test/node-unit/buffered-worker-pool.spec.js @@ -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' + ); + }); + }); + }); }); });