diff --git a/src/runners/junit4Runner/Junit4Runner.ts b/src/runners/junit4Runner/Junit4Runner.ts index 15f2856b..f9404c55 100644 --- a/src/runners/junit4Runner/Junit4Runner.ts +++ b/src/runners/junit4Runner/Junit4Runner.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -import { debug, DebugConfiguration, Uri, workspace } from 'vscode'; +import { debug, DebugConfiguration, DebugSession, Disposable, Uri, workspace } from 'vscode'; import { logger } from '../../logger/logger'; import { BaseRunner } from '../baseRunner/BaseRunner'; import { BaseRunnerResultAnalyzer } from '../baseRunner/BaseRunnerResultAnalyzer'; @@ -9,6 +9,20 @@ import { JUnit4RunnerResultAnalyzer } from './JUnit4RunnerResultAnalyzer'; export class JUnit4Runner extends BaseRunner { + private debugSession: DebugSession | undefined; + private disposables: Disposable[] = []; + + public async tearDown(isCancel: boolean): Promise { + super.tearDown(isCancel); + if (this.debugSession) { + this.debugSession.customRequest('disconnect'); + this.debugSession = undefined; + } + for (const disposable of this.disposables) { + disposable.dispose(); + } + } + protected get testResultAnalyzer(): BaseRunnerResultAnalyzer { if (!this.runnerResultAnalyzer) { this.runnerResultAnalyzer = new JUnit4RunnerResultAnalyzer(this.tests); @@ -24,6 +38,11 @@ export class JUnit4Runner extends BaseRunner { const uri: Uri = Uri.parse(this.tests[0].location.uri); logger.verbose(`Launching with the following launch configuration: '${JSON.stringify(launchConfiguration, null, 2)}'\n`); debug.startDebugging(workspace.getWorkspaceFolder(uri), launchConfiguration); + this.disposables.push(debug.onDidStartDebugSession((session: DebugSession) => { + if (launchConfiguration.name === session.name) { + this.debugSession = session; + } + })); } } diff --git a/src/utils/configUtils.ts b/src/utils/configUtils.ts index 3ff5a9cc..8e9923e2 100644 --- a/src/utils/configUtils.ts +++ b/src/utils/configUtils.ts @@ -187,6 +187,6 @@ async function migrate(configPath: string): Promise { workspaceConfig.update(CONFIG_SETTING_KEY, configItems, ConfigurationTarget.WorkspaceFolder); } -function randomSequence(): string { +export function randomSequence(): string { return crypto.randomBytes(3).toString('hex'); } diff --git a/src/utils/launchUtils.ts b/src/utils/launchUtils.ts index 60441fdf..2099e551 100644 --- a/src/utils/launchUtils.ts +++ b/src/utils/launchUtils.ts @@ -10,6 +10,7 @@ import { BaseRunner } from '../runners/baseRunner/BaseRunner'; import { IJUnitLaunchArguments } from '../runners/junit4Runner/Junit4Runner'; import { IRunnerContext } from '../runners/models'; import { resolveJUnitLaunchArguments, resolveRuntimeClassPath } from './commandUtils'; +import { randomSequence } from './configUtils'; export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, tests: ITestItem[], runnerContext: IRunnerContext, config?: IExecutionConfig): Promise { if (tests[0].kind === TestKind.JUnit) { @@ -24,7 +25,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te } return { - name: 'Launch Java Tests', + name: `Launch Java Tests - ${randomSequence()}`, type: 'java', request: 'launch', mainClass: runner.runnerMainClassName,