Fix os.cpus() and worker count in prepack test runner

Summary:
Turns out os.cpus() can return [] and undefined.

Additionally, it seems to me like any number below 4 could lead to an empty pool so I tried to address that too.

Reviewed By: NTillmann

Differential Revision: D8332896

fbshipit-source-id: 60e082a4f0d18e72f95b76732a50adeccb2d333d
This commit is contained in:
Peter van der Zee 2018-06-11 00:43:09 -07:00 committed by Facebook Github Bot
parent 3706b936c3
commit 485ea766fa

View File

@ -33,7 +33,8 @@ import minimist from "minimist";
import process from "process";
const EOL = os.EOL;
const numCPUs = os.cpus().length;
const cpus = os.cpus();
const numCPUs = cpus ? cpus.length : 1;
require("source-map-support").install();
type HarnessMap = { [key: string]: string };
@ -464,7 +465,7 @@ function masterRunMultiProcess(
const granularity = Math.floor(tests.length / 10);
const originalTestLength = tests.length;
// Fork workers.
const numWorkers = Math.floor(numCPUs * args.cpuScale);
const numWorkers = Math.max(1, Math.floor(numCPUs * args.cpuScale));
console.log(`Master starting up, forking ${numWorkers} workers`);
for (let i = 0; i < numWorkers; i++) {
cluster.fork();