Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix debug restart #24438

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/common/application/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DebugConsole,
DebugSession,
DebugSessionCustomEvent,
DebugSessionOptions,
Disposable,
Event,
WorkspaceFolder,
Expand Down Expand Up @@ -57,7 +58,7 @@ export class DebugService implements IDebugService {
public startDebugging(
folder: WorkspaceFolder | undefined,
nameOrConfiguration: string | DebugConfiguration,
parentSession?: DebugSession,
parentSession?: DebugSession | DebugSessionOptions,
): Thenable<boolean> {
return debug.startDebugging(folder, nameOrConfiguration, parentSession);
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable, named } from 'inversify';
import * as path from 'path';
import { DebugConfiguration, l10n, Uri, WorkspaceFolder, DebugSession } from 'vscode';
import { DebugConfiguration, l10n, Uri, WorkspaceFolder, DebugSession, DebugSessionOptions } from 'vscode';
import { IApplicationShell, IDebugService } from '../../common/application/types';
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import * as internalScripts from '../../common/process/internal/scripts';
Expand Down Expand Up @@ -32,7 +32,11 @@ export class DebugLauncher implements ITestDebugLauncher {
this.configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
}

public async launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void> {
public async launchDebugger(
options: LaunchOptions,
callback?: () => void,
sessionOptions?: DebugSessionOptions,
): Promise<void> {
const deferred = createDeferred<void>();
let hasCallbackBeenCalled = false;
if (options.token && options.token.isCancellationRequested) {
Expand All @@ -57,7 +61,7 @@ export class DebugLauncher implements ITestDebugLauncher {
const debugManager = this.serviceContainer.get<IDebugService>(IDebugService);

let activatedDebugSession: DebugSession | undefined;
debugManager.startDebugging(workspaceFolder, launchArgs).then(() => {
debugManager.startDebugging(workspaceFolder, launchArgs, sessionOptions).then(() => {
// Save the debug session after it is started so we can check if it is the one that was terminated.
activatedDebugSession = debugManager.activeDebugSession;
});
Expand Down
4 changes: 2 additions & 2 deletions src/client/testing/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CancellationToken, Disposable, OutputChannel, Uri } from 'vscode';
import { CancellationToken, DebugSessionOptions, Disposable, OutputChannel, Uri } from 'vscode';
import { Product } from '../../common/types';
import { TestSettingsPropertyNames } from '../configuration/types';
import { TestProvider } from '../types';
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface ITestConfigurationManagerFactory {
}
export const ITestDebugLauncher = Symbol('ITestDebugLauncher');
export interface ITestDebugLauncher {
launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void>;
launchDebugger(options: LaunchOptions, callback?: () => void, sessionOptions?: DebugSessionOptions): Promise<void>;
}

export const IUnitTestSocketServer = Symbol('IUnitTestSocketServer');
Expand Down
15 changes: 11 additions & 4 deletions src/client/testing/testController/pytest/pytestExecutionAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { CancellationTokenSource, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import * as path from 'path';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
Expand Down Expand Up @@ -167,10 +167,17 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
runTestIdsPort: testIdsFileName,
pytestPort: resultNamedPipeName,
};
const sessionOptions: DebugSessionOptions = {
testRun: runInstance,
};
traceInfo(`Running DEBUG pytest with arguments: ${testArgs} for workspace ${uri.fsPath} \r\n`);
await debugLauncher!.launchDebugger(launchOptions, () => {
serverCancel.cancel();
});
await debugLauncher!.launchDebugger(
launchOptions,
() => {
serverCancel.cancel();
},
sessionOptions,
);
} else {
// deferredTillExecClose is resolved when all stdout and stderr is read
const deferredTillExecClose: Deferred<void> = utils.createTestingDeferred();
Expand Down
15 changes: 11 additions & 4 deletions src/client/testing/testController/unittest/testExecutionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as path from 'path';
import { CancellationTokenSource, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import { ChildProcess } from 'child_process';
import { IConfigurationService, ITestOutputChannel } from '../../../common/types';
import { Deferred, createDeferred } from '../../../common/utils/async';
Expand Down Expand Up @@ -166,15 +166,22 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
runTestIdsPort: testIdsFileName,
pytestPort: resultNamedPipeName, // change this from pytest
};
const sessionOptions: DebugSessionOptions = {
testRun: runInstance,
};
traceInfo(`Running DEBUG unittest for workspace ${options.cwd} with arguments: ${args}\r\n`);

if (debugLauncher === undefined) {
traceError('Debug launcher is not defined');
throw new Error('Debug launcher is not defined');
}
await debugLauncher.launchDebugger(launchOptions, () => {
serverCancel.cancel();
});
await debugLauncher.launchDebugger(
launchOptions,
() => {
serverCancel.cancel();
},
sessionOptions,
);
} else {
// This means it is running the test
traceInfo(`Running unittests for workspace ${cwd} with arguments: ${args}\r\n`);
Expand Down
6 changes: 4 additions & 2 deletions src/test/testing/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ suite('Unit Tests - Debug Launcher', () => {
const deferred = createDeferred<void>();

debugService
.setup((d) => d.startDebugging(TypeMoq.It.isValue(workspaceFolder), TypeMoq.It.isValue(expected)))
.setup((d) =>
d.startDebugging(TypeMoq.It.isValue(workspaceFolder), TypeMoq.It.isValue(expected), undefined),
)
.returns((_wspc: WorkspaceFolder, _expectedParam: DebugConfiguration) => {
deferred.resolve();
return Promise.resolve(undefined as any);
Expand Down Expand Up @@ -299,7 +301,7 @@ suite('Unit Tests - Debug Launcher', () => {
});
test(`Must not launch debugger if cancelled ${testTitleSuffix}`, async () => {
debugService
.setup((d) => d.startDebugging(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.setup((d) => d.startDebugging(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => {
return Promise.resolve(undefined as any);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as assert from 'assert';
import { TestRun, Uri, TestRunProfileKind } from 'vscode';
import { TestRun, Uri, TestRunProfileKind, DebugSessionOptions } from 'vscode';
import * as typeMoq from 'typemoq';
import * as sinon from 'sinon';
import * as path from 'path';
Expand Down Expand Up @@ -238,7 +238,7 @@ suite('pytest test execution adapter', () => {
const deferred3 = createDeferred();
utilsWriteTestIdsFileStub.callsFake(() => Promise.resolve('testIdPipe-mockName'));
debugLauncher
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()))
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny(), typeMoq.It.isAny()))
.returns(async (_opts, callback) => {
traceInfo('stubs launch debugger');
if (typeof callback === 'function') {
Expand Down Expand Up @@ -273,6 +273,10 @@ suite('pytest test execution adapter', () => {
return true;
}),
typeMoq.It.isAny(),
typeMoq.It.is<DebugSessionOptions>((sessionOptions) => {
assert.equal(sessionOptions.testRun, testRun.object);
return true;
}),
),
typeMoq.Times.once(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ suite('Execution Flow Run Adapters', () => {

// debugLauncher mocked
debugLauncher
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()))
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny(), typeMoq.It.isAny()))
.callback((_options, callback) => {
if (callback) {
callback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as assert from 'assert';
import { TestRun, TestRunProfileKind, Uri } from 'vscode';
import { DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode';
import * as typeMoq from 'typemoq';
import * as sinon from 'sinon';
import * as path from 'path';
Expand Down Expand Up @@ -237,7 +237,7 @@ suite('Unittest test execution adapter', () => {
const deferred3 = createDeferred();
utilsWriteTestIdsFileStub.callsFake(() => Promise.resolve('testIdPipe-mockName'));
debugLauncher
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny()))
.setup((dl) => dl.launchDebugger(typeMoq.It.isAny(), typeMoq.It.isAny(), typeMoq.It.isAny()))
.returns(async (_opts, callback) => {
traceInfo('stubs launch debugger');
if (typeof callback === 'function') {
Expand Down Expand Up @@ -271,6 +271,10 @@ suite('Unittest test execution adapter', () => {
return true;
}),
typeMoq.It.isAny(),
typeMoq.It.is<DebugSessionOptions>((sessionOptions) => {
assert.equal(sessionOptions.testRun, testRun.object);
return true;
}),
),
typeMoq.Times.once(),
);
Expand Down
Loading