cli: make sure max workers workers are set to at least 2 by default

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-28 15:47:10 +01:00
parent d62ef69d55
commit 312a5d9f30
2 changed files with 15 additions and 1 deletions
+14
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import os from 'os';
import { Command, OptionValues } from 'commander';
import { PackageGraph } from '../../lib/monorepo';
import { paths } from '../../lib/paths';
@@ -91,6 +92,19 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
args.push('--workerIdleMemoryLimit=1000M');
}
// In order for the above worker memory limit to work we need to make sure the worker
// count is set to at least 2, as the tests will otherwise run in-band.
// Depending on the mode tests are run with the default count is either cpus-1, or cpus/2.
// This means that if we've got at 4 or more cores we'll always get at least 2 workers, but
// otherwise we need to set the worker count explicitly unless already done.
if (
os.cpus().length <= 3 &&
!includesAnyOf(args, '-i', '--runInBand') &&
!args.some(arg => arg.match(/^(--maxWorkers|-w)/))
) {
args.push('--maxWorkers=2');
}
if (opts.since) {
removeOptionArg(args, '--since');
}