From 478f4a9012fc903c11e9b76fcfda424a2d55999a Mon Sep 17 00:00:00 2001 From: Catink123 Date: Thu, 25 Aug 2022 18:56:22 +0300 Subject: [PATCH 1/3] Accommodate for os.cpus() bug --- lib/api.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index 1ebe27ce5..4636199cb 100644 --- a/lib/api.js +++ b/lib/api.js @@ -247,7 +247,8 @@ export default class Api extends Emittery { })); // Resolve the correct concurrency value. - let concurrency = Math.min(os.cpus().length, isCi ? 2 : Number.POSITIVE_INFINITY); + const cpuCount = os.cpus().length; + let concurrency = Math.min(cpuCount > 0 ? cpuCount : 1, isCi ? 2 : Number.POSITIVE_INFINITY); if (apiOptions.concurrency > 0) { concurrency = apiOptions.concurrency; } From 37d0d8a44d49a99f973d2b7c9107f0c5b37537d7 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Fri, 26 Aug 2022 14:47:31 +0200 Subject: [PATCH 2/3] Add comment and combine cases --- lib/api.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/api.js b/lib/api.js index 4636199cb..a6d9e57be 100644 --- a/lib/api.js +++ b/lib/api.js @@ -246,17 +246,18 @@ export default class Api extends Emittery { } })); - // Resolve the correct concurrency value. - const cpuCount = os.cpus().length; - let concurrency = Math.min(cpuCount > 0 ? cpuCount : 1, 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. + 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 = []; // Try and run each file, limited by `concurrency`. From 811a94dbe6dd9815bf77873bb23856bdfa2fbab2 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Fri, 26 Aug 2022 16:28:26 +0200 Subject: [PATCH 3/3] Fix linting and link to Node.js issue --- lib/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api.js b/lib/api.js index a6d9e57be..dcab0fab9 100644 --- a/lib/api.js +++ b/lib/api.js @@ -248,16 +248,16 @@ export default class Api extends Emittery { // 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 + concurrency = 2; } - const deregisteredSharedWorkers = []; // Try and run each file, limited by `concurrency`.