Skip to content

Commit d1c4754

Browse files
authored
Better-scheduled parallel tests (#18462)
* Out with the old... * Brave new world * Throttle console output * Batches test messages on large inputs initially * Move parallel runner code into seperate files
1 parent c522f37 commit d1c4754

File tree

9 files changed

+649
-591
lines changed

9 files changed

+649
-591
lines changed

Gulpfile.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import merge2 = require("merge2");
3131
import * as os from "os";
3232
import fold = require("travis-fold");
3333
const gulp = helpMaker(originalGulp);
34-
const mochaParallel = require("./scripts/mocha-parallel.js");
35-
const {runTestsInParallel} = mochaParallel;
3634

3735
Error.stackTraceLimit = 1000;
3836

@@ -668,26 +666,9 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
668666
}
669667
else {
670668
// run task to load all tests and partition them between workers
671-
const args = [];
672-
args.push("-R", "min");
673-
if (colors) {
674-
args.push("--colors");
675-
}
676-
else {
677-
args.push("--no-colors");
678-
}
679-
args.push(run);
680669
setNodeEnvToDevelopment();
681-
runTestsInParallel(taskConfigsFolder, run, { testTimeout, noColors: colors === " --no-colors " }, function(err) {
682-
// last worker clean everything and runs linter in case if there were no errors
683-
del(taskConfigsFolder).then(() => {
684-
if (!err) {
685-
lintThenFinish();
686-
}
687-
else {
688-
finish(err);
689-
}
690-
});
670+
exec(host, [run], lintThenFinish, function(e, status) {
671+
finish(e, status);
691672
});
692673
}
693674
});
@@ -711,7 +692,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
711692

712693
function finish(error?: any, errorStatus?: number) {
713694
restoreSavedNodeEnv();
714-
deleteTemporaryProjectOutput().then(() => {
695+
deleteTestConfig().then(deleteTemporaryProjectOutput).then(() => {
715696
if (error !== undefined || errorStatus !== undefined) {
716697
failWithStatus(error, errorStatus);
717698
}
@@ -720,6 +701,10 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
720701
}
721702
});
722703
}
704+
705+
function deleteTestConfig() {
706+
return del("test.config");
707+
}
723708
}
724709

725710
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) => {
@@ -836,7 +821,7 @@ function cleanTestDirs(done: (e?: any) => void) {
836821

837822
// used to pass data from jake command line directly to run.js
838823
function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?: string, workerCount?: number, stackTraceLimit?: string) {
839-
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder });
824+
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions["colors"] });
840825
console.log("Running tests with config: " + testConfigContents);
841826
fs.writeFileSync("test.config", testConfigContents);
842827
}

Jakefile.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// This file contains the build logic for the public repo
2+
// @ts-check
23

34
var fs = require("fs");
45
var os = require("os");
56
var path = require("path");
67
var child_process = require("child_process");
78
var fold = require("travis-fold");
8-
var runTestsInParallel = require("./scripts/mocha-parallel").runTestsInParallel;
99
var ts = require("./lib/typescript");
1010

1111

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

3939
function filesFromConfig(configPath) {
4040
var configText = fs.readFileSync(configPath).toString();
41-
var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true);
41+
var config = ts.parseConfigFileTextToJson(configPath, configText);
4242
if (config.error) {
4343
throw new Error(diagnosticsToString([config.error]));
4444
}
@@ -104,6 +104,9 @@ var harnessCoreSources = [
104104
"loggedIO.ts",
105105
"rwcRunner.ts",
106106
"test262Runner.ts",
107+
"./parallel/shared.ts",
108+
"./parallel/host.ts",
109+
"./parallel/worker.ts",
107110
"runner.ts"
108111
].map(function (f) {
109112
return path.join(harnessDirectory, f);
@@ -596,7 +599,7 @@ file(typesMapOutputPath, function() {
596599
var content = fs.readFileSync(path.join(serverDirectory, 'typesMap.json'));
597600
// Validate that it's valid JSON
598601
try {
599-
JSON.parse(content);
602+
JSON.parse(content.toString());
600603
} catch (e) {
601604
console.log("Parse error in typesMap.json: " + e);
602605
}
@@ -740,7 +743,7 @@ desc("Builds the test infrastructure using the built compiler");
740743
task("tests", ["local", run].concat(libraryTargets));
741744

742745
function exec(cmd, completeHandler, errorHandler) {
743-
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true });
746+
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true, interactive: true });
744747
// Add listeners for output and error
745748
ex.addListener("stdout", function (output) {
746749
process.stdout.write(output);
@@ -783,13 +786,14 @@ function cleanTestDirs() {
783786
}
784787

785788
// used to pass data from jake command line directly to run.js
786-
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit) {
789+
function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit, colors) {
787790
var testConfigContents = JSON.stringify({
788791
test: tests ? [tests] : undefined,
789792
light: light,
790793
workerCount: workerCount,
791794
taskConfigsFolder: taskConfigsFolder,
792-
stackTraceLimit: stackTraceLimit
795+
stackTraceLimit: stackTraceLimit,
796+
noColor: !colors
793797
});
794798
fs.writeFileSync('test.config', testConfigContents);
795799
}
@@ -831,7 +835,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
831835
}
832836

833837
if (tests || light || taskConfigsFolder) {
834-
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit);
838+
writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stackTraceLimit, colors);
835839
}
836840

837841
if (tests && tests.toLocaleLowerCase() === "rwc") {
@@ -894,19 +898,15 @@ function runConsoleTests(defaultReporter, runInParallel) {
894898
var savedNodeEnv = process.env.NODE_ENV;
895899
process.env.NODE_ENV = "development";
896900
var startTime = mark();
897-
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: !colors }, function (err) {
901+
exec(host + " " + run, function () {
898902
process.env.NODE_ENV = savedNodeEnv;
899903
measure(startTime);
900-
// last worker clean everything and runs linter in case if there were no errors
901-
deleteTemporaryProjectOutput();
902-
jake.rmRf(taskConfigsFolder);
903-
if (err) {
904-
fail(err);
905-
}
906-
else {
907-
runLinter();
908-
complete();
909-
}
904+
runLinter();
905+
finish();
906+
}, function (e, status) {
907+
process.env.NODE_ENV = savedNodeEnv;
908+
measure(startTime);
909+
finish(status);
910910
});
911911
}
912912

@@ -969,8 +969,8 @@ desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is
969969
task("runtests-browser", ["browserify", nodeServerOutFile], function () {
970970
cleanTestDirs();
971971
host = "node";
972-
browser = process.env.browser || process.env.b || (os.platform() === "linux" ? "chrome" : "IE");
973-
tests = process.env.test || process.env.tests || process.env.t;
972+
var browser = process.env.browser || process.env.b || (os.platform() === "linux" ? "chrome" : "IE");
973+
var tests = process.env.test || process.env.tests || process.env.t;
974974
var light = process.env.light || false;
975975
var testConfigFile = 'test.config';
976976
if (fs.existsSync(testConfigFile)) {

scripts/mocha-none-reporter.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)