Skip to content

Commit

Permalink
fix: Disconnect the debug session when cleaning up (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Sep 26, 2019
1 parent 3e5a421 commit d4e6315
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/runners/junit4Runner/Junit4Runner.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
// 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';
import { JUnit4RunnerResultAnalyzer } from './JUnit4RunnerResultAnalyzer';

export class JUnit4Runner extends BaseRunner {

private debugSession: DebugSession | undefined;
private disposables: Disposable[] = [];

public async tearDown(isCancel: boolean): Promise<void> {
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);
Expand All @@ -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;
}
}));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/configUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ async function migrate(configPath: string): Promise<void> {
workspaceConfig.update(CONFIG_SETTING_KEY, configItems, ConfigurationTarget.WorkspaceFolder);
}

function randomSequence(): string {
export function randomSequence(): string {
return crypto.randomBytes(3).toString('hex');
}
3 changes: 2 additions & 1 deletion src/utils/launchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugConfiguration> {
if (tests[0].kind === TestKind.JUnit) {
Expand All @@ -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,
Expand Down

0 comments on commit d4e6315

Please sign in to comment.