From: Jérôme Benoit Date: Mon, 28 Aug 2023 15:57:54 +0000 (+0200) Subject: test: refine UTs X-Git-Tag: v2.6.37~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=562a40378f9221d89759ddf99a675324ef4deb02;p=poolifier.git test: refine UTs Signed-off-by: Jérôme Benoit --- diff --git a/rollup.config.mjs b/rollup.config.mjs index e40f170d..90d56e60 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -10,9 +10,9 @@ const availableParallelism = () => { try { availableParallelism = os.availableParallelism() } catch { - const numberOfCpus = os.cpus() - if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { - availableParallelism = numberOfCpus.length + const cpus = os.cpus() + if (Array.isArray(cpus) && cpus.length > 0) { + availableParallelism = cpus.length } } return availableParallelism diff --git a/src/utils.ts b/src/utils.ts index 82c38c09..e1d6c118 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -59,9 +59,9 @@ export const availableParallelism = (): number => { try { availableParallelism = os.availableParallelism() } catch { - const numberOfCpus = os.cpus() - if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { - availableParallelism = numberOfCpus.length + const cpus = os.cpus() + if (Array.isArray(cpus) && cpus.length > 0) { + availableParallelism = cpus.length } } return availableParallelism diff --git a/tests/utils.test.js b/tests/utils.test.js index b91929a6..fdb67478 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,6 +1,7 @@ const { randomInt } = require('crypto') const { Worker } = require('worker_threads') const cluster = require('cluster') +const os = require('os') const { expect } = require('expect') const { CircularArray, @@ -56,7 +57,13 @@ describe('Utils test suite', () => { it('Verify availableParallelism() behavior', () => { const parallelism = availableParallelism() expect(typeof parallelism === 'number').toBe(true) - expect(parallelism).toBeGreaterThan(0) + let expectedParallelism = 1 + try { + expectedParallelism = os.availableParallelism() + } catch { + expectedParallelism = os.cpus().length + } + expect(parallelism).toBe(expectedParallelism) expect(Number.isSafeInteger(parallelism)).toBe(true) })