Skip to content

[engineering] split unit tests to run in parallel #252921

Open
@tmm1

Description

@tmm1

I have been experimenting with running tests in parallel

mocha itself has a parallel mode, but it's only suitable for nodejs tests

A similar technique can be emulated by splitting tests and spawning off multiple test runners. i added a simple patch that can be used as so:

scripts/test.sh --testSplit 2/2

However, I am seeing failures when running specific portions of the test suite.

On main, with the patch below and the command above I see:

  1) TerminalLinkParsing
       "before each" hook in "TerminalLinkParsing":


      + expected - actual


  Error: done() called multiple times in hook <TerminalLinkParsing "before each" hook in "TerminalLinkParsing"> of file vs/workbench/contrib/terminalContrib/links/test/browser/terminalLinkParsing.test; in addition, done() received error: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

  2 !== 0
diff --git a/vscode/test/unit/electron/index.js b/vscode/test/unit/electron/index.js
index f69104799ca..14d298646fa 100644
--- a/vscode/test/unit/electron/index.js
+++ b/vscode/test/unit/electron/index.js
@@ -30,6 +30,7 @@ const minimist = require('minimist');
  * grep: string;
  * run: string;
  * runGlob: string;
+ * testSplit: string;
  * dev: boolean;
  * reporter: string;
  * 'reporter-options': string;
@@ -46,7 +47,7 @@ const minimist = require('minimist');
  * }}
  */
 const args = minimist(process.argv.slice(2), {
-	string: ['grep', 'run', 'runGlob', 'reporter', 'reporter-options', 'waitServer', 'timeout', 'crash-reporter-directory', 'tfs', 'coveragePath', 'coverageFormats'],
+	string: ['grep', 'run', 'runGlob', 'reporter', 'reporter-options', 'waitServer', 'timeout', 'crash-reporter-directory', 'tfs', 'coveragePath', 'coverageFormats', 'testSplit'],
 	boolean: ['build', 'coverage', 'help', 'dev', 'per-test-coverage'],
 	alias: {
 		'grep': ['g', 'f'],
@@ -67,6 +68,7 @@ Options:
 --grep, -g, -f <pattern>      only run tests matching <pattern>
 --run <file>                  only run tests from <file>
 --runGlob, --glob, --runGrep <file_pattern> only run tests matching <file_pattern>
+--testSplit <i>/<n>           split tests into <n> parts and run the <i>th part
 --build                       run with build output (out-build)
 --coverage                    generate coverage report
 --per-test-coverage           generate a per-test V8 coverage report, only valid with the full-json-stream reporter
diff --git a/vscode/test/unit/electron/renderer.js b/vscode/test/unit/electron/renderer.js
index ffda4fbe5c9..6bb75c7819d 100644
--- a/vscode/test/unit/electron/renderer.js
+++ b/vscode/test/unit/electron/renderer.js
@@ -172,7 +172,14 @@ async function loadTestModules(opts) {
 
 	const pattern = opts.runGlob || _tests_glob;
 	const files = await globAsync(pattern, { cwd: loadFn._out });
-	const modules = files.map(file => file.replace(/\.js$/, ''));
+	let modules = files.map(file => file.replace(/\.js$/, ''));
+	if (opts.testSplit) {
+		const [i, n] = opts.testSplit.split('/').map(Number);
+		const chunkSize = Math.floor(modules.length / n);
+		const start = (i - 1) * chunkSize;
+		const end = i === n ? modules.length : i * chunkSize;
+		modules = modules.slice(start, end);
+	}
 	return loadModules(modules);
 }
 

cc @joaomoreno who did some similar work in #241847

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions