2017-08-05 05:00:16 +03:00
|
|
|
import * as os from "os";
|
2017-08-13 04:23:54 +03:00
|
|
|
import * as _ from "lodash";
|
2017-08-05 05:00:16 +03:00
|
|
|
|
|
|
|
import { inParallel } from "./lib/multicore";
|
2018-04-29 01:08:43 +03:00
|
|
|
import { execAsync, Sample } from "./utils";
|
2017-10-23 16:38:47 +03:00
|
|
|
import { Fixture, allFixtures } from "./fixtures";
|
2018-02-16 04:41:55 +03:00
|
|
|
import { affectedFixtures, divideParallelJobs } from "./buildkite";
|
2017-08-05 05:00:16 +03:00
|
|
|
|
2017-09-11 07:08:10 +03:00
|
|
|
const exit = require("exit");
|
2017-09-29 13:06:26 +03:00
|
|
|
const CPUs = parseInt(process.env.CPUs || "0", 10) || os.cpus().length;
|
2017-07-31 21:22:53 +03:00
|
|
|
|
2017-08-01 23:21:49 +03:00
|
|
|
//////////////////////////////////////
|
|
|
|
// Test driver
|
|
|
|
/////////////////////////////////////
|
|
|
|
|
2018-02-16 04:41:55 +03:00
|
|
|
export type WorkItem = { sample: Sample; fixtureName: string };
|
2017-08-15 02:38:33 +03:00
|
|
|
|
2017-09-10 09:02:45 +03:00
|
|
|
async function main(sources: string[]) {
|
2017-09-24 18:29:38 +03:00
|
|
|
let fixtures = allFixtures;
|
2017-09-29 13:06:26 +03:00
|
|
|
const fixturesFromCmdline = process.env.FIXTURE;
|
|
|
|
if (fixturesFromCmdline) {
|
|
|
|
const fixtureNames = fixturesFromCmdline.split(",");
|
2018-02-16 04:41:55 +03:00
|
|
|
fixtures = _.filter(fixtures, fixture => _.some(fixtureNames, name => fixture.runForName(name)));
|
|
|
|
} else {
|
|
|
|
fixtures = affectedFixtures();
|
|
|
|
if (allFixtures.length !== fixtures.length) {
|
|
|
|
console.error(`* Running a subset of fixtures: ${fixtures.map(f => f.name).join(", ")}`);
|
|
|
|
}
|
2017-09-24 18:29:38 +03:00
|
|
|
}
|
2017-09-29 13:06:26 +03:00
|
|
|
// Get an array of all { sample, fixtureName } objects we'll run.
|
|
|
|
// We can't just put the fixture in there because these WorkItems
|
|
|
|
// will be sent in a message, removing all code.
|
2017-09-24 18:29:38 +03:00
|
|
|
const samples = _.map(fixtures, fixture => ({
|
2017-09-11 07:08:10 +03:00
|
|
|
fixtureName: fixture.name,
|
|
|
|
samples: fixture.getSamples(sources)
|
|
|
|
}));
|
|
|
|
const priority = _.flatMap(samples, x =>
|
|
|
|
_.map(x.samples.priority, s => ({ fixtureName: x.fixtureName, sample: s }))
|
|
|
|
);
|
|
|
|
const others = _.flatMap(samples, x =>
|
|
|
|
_.map(x.samples.others, s => ({ fixtureName: x.fixtureName, sample: s }))
|
|
|
|
);
|
|
|
|
|
2018-02-16 04:41:55 +03:00
|
|
|
const tests = divideParallelJobs(_.concat(priority, others));
|
2017-09-11 07:08:10 +03:00
|
|
|
|
|
|
|
await inParallel({
|
|
|
|
queue: tests,
|
|
|
|
workers: CPUs,
|
|
|
|
|
|
|
|
setup: async () => {
|
|
|
|
testCLI();
|
|
|
|
|
2018-03-06 23:43:30 +03:00
|
|
|
console.error(`* Running ${tests.length} tests between ${fixtures.length} fixtures`);
|
2017-09-11 07:08:10 +03:00
|
|
|
|
2017-09-24 18:29:38 +03:00
|
|
|
for (const fixture of fixtures) {
|
2017-12-29 01:35:43 +03:00
|
|
|
await execAsync(`rm -rf test/runs`);
|
|
|
|
await execAsync(`mkdir -p test/runs`);
|
2017-09-11 07:08:10 +03:00
|
|
|
|
|
|
|
await fixture.setup();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
map: async ({ sample, fixtureName }: WorkItem, index) => {
|
2017-09-29 13:06:26 +03:00
|
|
|
let fixture = _.find(fixtures, { name: fixtureName }) as Fixture;
|
2017-09-11 07:08:10 +03:00
|
|
|
try {
|
|
|
|
await fixture.runWithSample(sample, index, tests.length);
|
|
|
|
} catch (e) {
|
|
|
|
console.trace(e);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-25 18:55:37 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 19:57:06 +03:00
|
|
|
function testCLI() {
|
2017-09-11 07:08:10 +03:00
|
|
|
console.log(`* CLI sanity check`);
|
2018-04-29 01:08:43 +03:00
|
|
|
//const qt = (args: string) => exec(`node dist/cli/index.js ${args}`);
|
2017-11-03 04:08:08 +03:00
|
|
|
|
2018-04-29 01:08:43 +03:00
|
|
|
//console.log("* Ensure we can quicktype a URL");
|
|
|
|
//qt(`https://blockchain.info/latestblock`);
|
2017-08-15 19:57:06 +03:00
|
|
|
}
|
|
|
|
|
2017-07-26 04:56:38 +03:00
|
|
|
// skip 2 `node` args
|
2017-08-15 06:48:15 +03:00
|
|
|
main(process.argv.slice(2)).catch(reason => {
|
2017-09-11 07:08:10 +03:00
|
|
|
console.error(reason);
|
|
|
|
process.exit(1);
|
2017-09-01 19:05:04 +03:00
|
|
|
});
|