From 3399e8f47d2c1e8fc5f6c5e93b94b978162b9e99 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Mon, 26 Dec 2022 22:30:19 -0500 Subject: [PATCH] chore: use os.availableParallelism() This commit addresses an existing TODO in the code by moving to the new os.availableParallelism() instead of os.cpus().length. PR-URL: https://github.com/nodejs/node/pull/45969 Reviewed-By: Yagiz Nizipli Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Antoine du Hamel (cherry picked from commit fe5710effcb0b336853657e424da04407b0e49ad) --- lib/internal/test_runner/test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index f2e8e41..f1d15ad 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -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' @@ -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 }