Skip to content

Commit

Permalink
support sequential tests in parallel executor
Browse files Browse the repository at this point in the history
Signed-off-by: Jannik Glückert <jannik.glueckert@gmail.com>
  • Loading branch information
Jannik2099 committed Sep 21, 2024
1 parent d7824ad commit 4ce57c8
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,55 +26,66 @@ export async function testRunHandler(
token: vscode.CancellationToken,
) {
const run = controller.createTestRun(request, undefined, false);
const queue: vscode.TestItem[] = [];
const parallelTests: vscode.TestItem[] = [];
const sequentialTests: vscode.TestItem[] = [];

const buildDir = workspaceState.get<string>("mesonbuild.buildDir")!;
const mesonTests = await getMesonTests(buildDir);

function testAdder(test: vscode.TestItem) {
const mesonTest = mesonTests.find((mesonTest) => {
return mesonTest.name == test.id;
})!;
if (mesonTest.is_parallel) {
parallelTests.push(test);
} else {
sequentialTests.push(test);
}
// this way the total number of runs shows up from the beginning,
// instead of incrementing as individual runs finish
run.enqueued(test);
}
if (request.include) {
request.include.forEach((test) => queue.push(test));
request.include.forEach(testAdder);
} else {
controller.items.forEach((test) => queue.push(test));
controller.items.forEach(testAdder);
}

// this way the total number of runs shows up from the beginning,
// instead of incrementing as individual runs finish
for (const test of queue) {
run.enqueued(test);
function dispatchTest(test: vscode.TestItem) {
run.started(test);
return exec(
extensionConfiguration("mesonPath"),
["test", "-C", buildDir, "--print-errorlog", `"${test.id}"`],
extensionConfiguration("testEnvironment"),
).then(
(onfulfilled) => {
run.passed(test, onfulfilled.time);
},
(onrejected) => {
const execResult = onrejected as ExecResult;

let stdout = execResult.stdout;
if (os.platform() != "win32") {
stdout = stdout.replace(/\n/g, "\r\n");
}
run.appendOutput(stdout, undefined, test);
if (execResult.error?.code == 125) {
vscode.window.showErrorMessage("Failed to build tests. Results will not be updated");
run.errored(test, new vscode.TestMessage(execResult.stderr));
} else {
run.failed(test, new vscode.TestMessage(execResult.stderr), execResult.time);
}
},
);
}

const buildDir = workspaceState.get<string>("mesonbuild.buildDir")!;

const running_tests: Promise<void>[] = [];
const max_running = os.cpus().length;

for (const test of queue) {
run.started(test);
const running_test = exec(
extensionConfiguration("mesonPath"),
["test", "-C", buildDir, "--print-errorlog", `"${test.id}"`],
extensionConfiguration("testEnvironment"),
)
.then(
(onfulfilled) => {
run.passed(test, onfulfilled.time);
},
(onrejected) => {
const execResult = onrejected as ExecResult;

let stdout = execResult.stdout;
if (os.platform() != "win32") {
stdout = stdout.replace(/\n/g, "\r\n");
}
run.appendOutput(stdout, undefined, test);
if (execResult.error?.code == 125) {
vscode.window.showErrorMessage("Failed to build tests. Results will not be updated");
run.errored(test, new vscode.TestMessage(execResult.stderr));
} else {
run.failed(test, new vscode.TestMessage(execResult.stderr), execResult.time);
}
},
)
.finally(() => {
running_tests.splice(running_tests.indexOf(running_test), 1);
});
for (const test of parallelTests) {
const running_test = dispatchTest(test).finally(() => {
running_tests.splice(running_tests.indexOf(running_test), 1);
});

running_tests.push(running_test);

Expand All @@ -84,6 +95,10 @@ export async function testRunHandler(
}
await Promise.all(running_tests);

for (const test of sequentialTests) {
await dispatchTest(test);
}

run.end();
}

Expand Down

0 comments on commit 4ce57c8

Please sign in to comment.