From 7ae24abd7b3df0dbcd689d2915b016bbdb5dfb34 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Mon, 26 Dec 2022 22:30:19 -0500 Subject: [PATCH] test_runner: 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 --- lib/internal/test_runner/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 8b0ba16f1a6a79..6f1c29d1def6a0 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -53,7 +53,7 @@ const { } = require('internal/validators'); const { setTimeout } = require('timers/promises'); const { TIMEOUT_MAX } = require('internal/timers'); -const { cpus } = require('os'); +const { availableParallelism } = require('os'); const { bigint: hrtime } = process.hrtime; const kCallbackAndPromisePresent = 'callbackAndPromisePresent'; const kCancelledByParent = 'cancelledByParent'; @@ -217,8 +217,8 @@ class Test extends AsyncResource { case 'boolean': if (concurrency) { - // TODO(cjihrig): Use uv_available_parallelism() once it lands. - this.concurrency = parent === null ? MathMax(cpus().length - 1, 1) : Infinity; + this.concurrency = parent === null ? + MathMax(availableParallelism() - 1, 1) : Infinity; } else { this.concurrency = 1; }