Skip to content

Commit

Permalink
chore: use os.availableParallelism()
Browse files Browse the repository at this point in the history
This commit addresses an existing TODO in the code by moving
to the new os.availableParallelism() instead of os.cpus().length.

PR-URL: nodejs/node#45969
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
(cherry picked from commit fe5710effcb0b336853657e424da04407b0e49ad)
  • Loading branch information
cjihrig authored and MoLow committed Feb 8, 2023
1 parent a5e0e9e commit a64358a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/test_runner/test.js
Expand Up @@ -56,7 +56,7 @@ const {
} = require('#internal/validators')
const { setTimeout } = require('#timers/promises')
const { TIMEOUT_MAX } = require('#internal/timers')
const { cpus } = require('os')
const { cpus, availableParallelism } = require('os')
const { bigint: hrtime } = process.hrtime
const kCallbackAndPromisePresent = 'callbackAndPromisePresent'
const kCancelledByParent = 'cancelledByParent'
Expand Down Expand Up @@ -205,7 +205,9 @@ class Test extends AsyncResource {

case 'boolean':
if (concurrency) {
this.concurrency = parent === null ? MathMax(cpus().length - 1, 1) : Infinity
this.concurrency = parent === null
? MathMax((typeof availableParallelism === 'undefined' ? cpus().length : availableParallelism()) - 1, 1)
: Infinity
} else {
this.concurrency = 1
}
Expand Down

0 comments on commit a64358a

Please sign in to comment.