Skip to content

Commit d4e6315

Browse files
authored
fix: Disconnect the debug session when cleaning up (microsoft#822)
1 parent 3e5a421 commit d4e6315

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/runners/junit4Runner/Junit4Runner.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { debug, DebugConfiguration, Uri, workspace } from 'vscode';
4+
import { debug, DebugConfiguration, DebugSession, Disposable, Uri, workspace } from 'vscode';
55
import { logger } from '../../logger/logger';
66
import { BaseRunner } from '../baseRunner/BaseRunner';
77
import { BaseRunnerResultAnalyzer } from '../baseRunner/BaseRunnerResultAnalyzer';
88
import { JUnit4RunnerResultAnalyzer } from './JUnit4RunnerResultAnalyzer';
99

1010
export class JUnit4Runner extends BaseRunner {
1111

12+
private debugSession: DebugSession | undefined;
13+
private disposables: Disposable[] = [];
14+
15+
public async tearDown(isCancel: boolean): Promise<void> {
16+
super.tearDown(isCancel);
17+
if (this.debugSession) {
18+
this.debugSession.customRequest('disconnect');
19+
this.debugSession = undefined;
20+
}
21+
for (const disposable of this.disposables) {
22+
disposable.dispose();
23+
}
24+
}
25+
1226
protected get testResultAnalyzer(): BaseRunnerResultAnalyzer {
1327
if (!this.runnerResultAnalyzer) {
1428
this.runnerResultAnalyzer = new JUnit4RunnerResultAnalyzer(this.tests);
@@ -24,6 +38,11 @@ export class JUnit4Runner extends BaseRunner {
2438
const uri: Uri = Uri.parse(this.tests[0].location.uri);
2539
logger.verbose(`Launching with the following launch configuration: '${JSON.stringify(launchConfiguration, null, 2)}'\n`);
2640
debug.startDebugging(workspace.getWorkspaceFolder(uri), launchConfiguration);
41+
this.disposables.push(debug.onDidStartDebugSession((session: DebugSession) => {
42+
if (launchConfiguration.name === session.name) {
43+
this.debugSession = session;
44+
}
45+
}));
2746
}
2847
}
2948

src/utils/configUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,6 @@ async function migrate(configPath: string): Promise<void> {
187187
workspaceConfig.update(CONFIG_SETTING_KEY, configItems, ConfigurationTarget.WorkspaceFolder);
188188
}
189189

190-
function randomSequence(): string {
190+
export function randomSequence(): string {
191191
return crypto.randomBytes(3).toString('hex');
192192
}

src/utils/launchUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BaseRunner } from '../runners/baseRunner/BaseRunner';
1010
import { IJUnitLaunchArguments } from '../runners/junit4Runner/Junit4Runner';
1111
import { IRunnerContext } from '../runners/models';
1212
import { resolveJUnitLaunchArguments, resolveRuntimeClassPath } from './commandUtils';
13+
import { randomSequence } from './configUtils';
1314

1415
export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, tests: ITestItem[], runnerContext: IRunnerContext, config?: IExecutionConfig): Promise<DebugConfiguration> {
1516
if (tests[0].kind === TestKind.JUnit) {
@@ -24,7 +25,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te
2425
}
2526

2627
return {
27-
name: 'Launch Java Tests',
28+
name: `Launch Java Tests - ${randomSequence()}`,
2829
type: 'java',
2930
request: 'launch',
3031
mainClass: runner.runnerMainClassName,

0 commit comments

Comments
 (0)