Skip to content

Commit

Permalink
Command for triggering running tests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovic-d committed Dec 6, 2024
1 parent dfed159 commit cb073da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
8 changes: 5 additions & 3 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,12 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
}
};

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel', async (projects?) => {
testAdapter?.runTestsWithParallelParallel(projects);
}));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel.createProfile', async (projects?) => {
if (projects) {
testAdapter?.registerRunInParallelProfile(projects);
}
testAdapter?.registerRunInParallelProfile(projects);
}));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test', async (uri, methodName?, launchConfiguration?, testInParallel?, projects?) => {
Expand Down
36 changes: 27 additions & 9 deletions java/java.lsp.server/vscode/src/testAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
'use strict';

import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile } from "vscode";
import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile, CancellationTokenSource } from "vscode";
import * as path from 'path';
import { asRange, TestCase, TestSuite } from "./protocol";
import { COMMAND_PREFIX, listeners, TEST_PROGRESS_EVENT } from "./extension";
Expand All @@ -33,6 +33,7 @@ export class NbTestAdapter {
private itemsToRun: Set<TestItem> | undefined;
private started: boolean = false;
private suiteStates: Map<TestItem, SuiteState>;
private parallelRunProfile: TestRunProfile | undefined;

constructor() {
this.testController = tests.createTestController('apacheNetBeansController', 'Apache NetBeans');
Expand All @@ -46,7 +47,15 @@ export class NbTestAdapter {

public registerRunInParallelProfile(projects: string[]) {
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
this.testController.items.replace([]);
this.load();
}

public runTestsWithParallelParallel(projects?: string[]) {
if (this.parallelRunProfile) {
this.run(new TestRunRequest(undefined, undefined, this.parallelRunProfile), new CancellationTokenSource().token, true, projects);
}
}

async load(): Promise<void> {
Expand Down Expand Up @@ -198,7 +207,7 @@ export class NbTestAdapter {
}

testProgress(suite: TestSuite): void {
const currentModule = this.testController.items.get(this.getModuleName(suite));
const currentModule = this.testController.items.get(suite.moduleName || "");
const currentSuite = currentModule?.children.get(suite.name);

switch (suite.state) {
Expand Down Expand Up @@ -287,10 +296,11 @@ export class NbTestAdapter {
}

updateTests(suite: TestSuite, testExecution?: boolean): void {
const moduleName = this.getModuleName(suite);
const moduleName = suite.moduleName || "";
let currentModule = this.testController.items.get(moduleName);
if (!currentModule) {
currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(moduleName, 'module'), this.getModulePath(suite));
const parsedName = this.parseModuleName(moduleName);
currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(parsedName, 'module'), this.getModulePath(suite));
this.testController.items.add(currentModule);
}

Expand Down Expand Up @@ -360,11 +370,19 @@ export class NbTestAdapter {
currentModule.children.replace(suiteChildren);
}
}

getModuleName(suite: TestSuite): string {
return suite.moduleName?.replace(":", "-") || "";

parseModuleName(moduleName: string): string {
if (!this.parallelRunProfile) {
return moduleName.replace(":", "-");
}
const index = moduleName.indexOf(":");
if (index !== -1) {
return moduleName.slice(index + 1);
}
const parts = moduleName.split("-");
return parts[parts.length - 1];
}

getModulePath(suite: TestSuite): Uri {
return Uri.parse(suite.modulePath || "");
}
Expand Down

0 comments on commit cb073da

Please sign in to comment.