Skip to content

Commit

Permalink
Better-scheduled parallel tests (#18462)
Browse files Browse the repository at this point in the history
* Out with the old...

* Brave new world

* Throttle console output

* Batches test messages on large inputs initially

* Move parallel runner code into seperate files
  • Loading branch information
weswigham authored Sep 14, 2017
1 parent c522f37 commit d1c4754
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 591 deletions.
31 changes: 8 additions & 23 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import merge2 = require("merge2");
import * as os from "os";
import fold = require("travis-fold");
const gulp = helpMaker(originalGulp);
const mochaParallel = require("./scripts/mocha-parallel.js");
const {runTestsInParallel} = mochaParallel;

Error.stackTraceLimit = 1000;

Expand Down Expand Up @@ -668,26 +666,9 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
}
else {
// run task to load all tests and partition them between workers
const args = [];
args.push("-R", "min");
if (colors) {
args.push("--colors");
}
else {
args.push("--no-colors");
}
args.push(run);
setNodeEnvToDevelopment();
runTestsInParallel(taskConfigsFolder, run, { testTimeout, noColors: colors === " --no-colors " }, function(err) {
// last worker clean everything and runs linter in case if there were no errors
del(taskConfigsFolder).then(() => {
if (!err) {
lintThenFinish();
}
else {
finish(err);
}
});
exec(host, [run], lintThenFinish, function(e, status) {
finish(e, status);
});
}
});
Expand All @@ -711,7 +692,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:

function finish(error?: any, errorStatus?: number) {
restoreSavedNodeEnv();
deleteTemporaryProjectOutput().then(() => {
deleteTestConfig().then(deleteTemporaryProjectOutput).then(() => {
if (error !== undefined || errorStatus !== undefined) {
failWithStatus(error, errorStatus);
}
Expand All @@ -720,6 +701,10 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
}
});
}

function deleteTestConfig() {
return del("test.config");
}
}

gulp.task("runtests-parallel", "Runs all the tests in parallel using the built run.js file. Optional arguments are: --t[ests]=category1|category2|... --d[ebug]=true.", ["build-rules", "tests"], (done) => {
Expand Down Expand Up @@ -836,7 +821,7 @@ function cleanTestDirs(done: (e?: any) => void) {

// used to pass data from jake command line directly to run.js
function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?: string, workerCount?: number, stackTraceLimit?: string) {
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder });
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions["colors"] });
console.log("Running tests with config: " + testConfigContents);
fs.writeFileSync("test.config", testConfigContents);
}
Expand Down
40 changes: 20 additions & 20 deletions Jakefile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This file contains the build logic for the public repo
// @ts-check

var fs = require("fs");
var os = require("os");
var path = require("path");
var child_process = require("child_process");
var fold = require("travis-fold");
var runTestsInParallel = require("./scripts/mocha-parallel").runTestsInParallel;
var ts = require("./lib/typescript");


Expand Down Expand Up @@ -38,7 +38,7 @@ else if (process.env.PATH !== undefined) {

function filesFromConfig(configPath) {
var configText = fs.readFileSync(configPath).toString();
var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true);
var config = ts.parseConfigFileTextToJson(configPath, configText);
if (config.error) {
throw new Error(diagnosticsToString([config.error]));
}
Expand Down Expand Up @@ -104,6 +104,9 @@ var harnessCoreSources = [
"loggedIO.ts",
"rwcRunner.ts",
"test262Runner.ts",
"./parallel/shared.ts",
"./parallel/host.ts",
"./parallel/worker.ts",
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
Expand Down Expand Up @@ -596,7 +599,7 @@ file(typesMapOutputPath, function() {
var content = fs.readFileSync(path.join(serverDirectory, 'typesMap.json'));
// Validate that it's valid JSON
try {
JSON.parse(content);
JSON.parse(content.toString());
} catch (e) {
console.log("Parse error in typesMap.json: " + e);
}
Expand Down Expand Up @@ -740,7 +743,7 @@ desc("Builds the test infrastructure using the built compiler");
task("tests", ["local", run].concat(libraryTargets));

function exec(cmd, completeHandler, errorHandler) {
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true });
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true, interactive: true });
// Add listeners for output and error
ex.addListener("stdout", function (output) {
process.stdout.write(output);
Expand Down Expand Up @@ -783,13 +786,14 @@ function cleanTestDirs() {
}

// used to pass data from jake command line directly to run.js
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit) {
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit, colors) {
var testConfigContents = JSON.stringify({
test: tests ? [tests] : undefined,
light: light,
workerCount: workerCount,
taskConfigsFolder: taskConfigsFolder,
stackTraceLimit: stackTraceLimit
stackTraceLimit: stackTraceLimit,
noColor: !colors
});
fs.writeFileSync('test.config', testConfigContents);
}
Expand Down Expand Up @@ -831,7 +835,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
}

if (tests || light || taskConfigsFolder) {
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit);
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit, colors);
}

if (tests && tests.toLocaleLowerCase() === "rwc") {
Expand Down Expand Up @@ -894,19 +898,15 @@ function runConsoleTests(defaultReporter, runInParallel) {
var savedNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = "development";
var startTime = mark();
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: !colors }, function (err) {
exec(host + " " + run, function () {
process.env.NODE_ENV = savedNodeEnv;
measure(startTime);
// last worker clean everything and runs linter in case if there were no errors
deleteTemporaryProjectOutput();
jake.rmRf(taskConfigsFolder);
if (err) {
fail(err);
}
else {
runLinter();
complete();
}
runLinter();
finish();
}, function (e, status) {
process.env.NODE_ENV = savedNodeEnv;
measure(startTime);
finish(status);
});
}

Expand Down Expand Up @@ -969,8 +969,8 @@ desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is
task("runtests-browser", ["browserify", nodeServerOutFile], function () {
cleanTestDirs();
host = "node";
browser = process.env.browser || process.env.b || (os.platform() === "linux" ? "chrome" : "IE");
tests = process.env.test || process.env.tests || process.env.t;
var browser = process.env.browser || process.env.b || (os.platform() === "linux" ? "chrome" : "IE");
var tests = process.env.test || process.env.tests || process.env.t;
var light = process.env.light || false;
var testConfigFile = 'test.config';
if (fs.existsSync(testConfigFile)) {
Expand Down
26 changes: 0 additions & 26 deletions scripts/mocha-none-reporter.js

This file was deleted.

Loading

0 comments on commit d1c4754

Please sign in to comment.