From 4b03662cbc349f94d74989a8d500113d620d2445 Mon Sep 17 00:00:00 2001 From: Catink123 Date: Sat, 27 Aug 2022 18:58:06 +0300 Subject: [PATCH] Work around os.cpus() returning an empty array on unsupported platforms `os.cpus()` can return empty arrays on platforms not officially supported by Node.js. Use 1 as a minimum. See . Co-authored-by: Mark Wubben --- lib/api.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/api.js b/lib/api.js index 1ebe27ce5..dcab0fab9 100644 --- a/lib/api.js +++ b/lib/api.js @@ -246,14 +246,16 @@ export default class Api extends Emittery { } })); - // Resolve the correct concurrency value. - let concurrency = Math.min(os.cpus().length, isCi ? 2 : Number.POSITIVE_INFINITY); - if (apiOptions.concurrency > 0) { - concurrency = apiOptions.concurrency; - } - + // Resolve the correct concurrency value. Note that `os.cpus()` can return empty arrays on + // platforms not officially supported by Node.js. Use 1 as a minimum. + // See . + let concurrency = Math.max(1, os.cpus().length); if (apiOptions.serial) { concurrency = 1; + } else if (apiOptions.concurrency > 0) { + concurrency = apiOptions.concurrency; + } else if (isCi) { + concurrency = 2; } const deregisteredSharedWorkers = [];