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
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
const { randomInt } = require('crypto')
const { Worker } = require('worker_threads')
const cluster = require('cluster')
+const os = require('os')
const { expect } = require('expect')
const {
CircularArray,
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)
})