Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around os.cpus() returning an empty array on unsupported platforms #3095

Merged
merged 5 commits into from Aug 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/api.js
Expand Up @@ -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 <https://github.com/nodejs/node/issues/38190>.
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 = [];
Expand Down