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 bug so canceling debug works in rewrite #21361

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DebugLauncher implements ITestDebugLauncher {
this.configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
}

public async launchDebugger(options: LaunchOptions): Promise<void> {
public async launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void> {
if (options.token && options.token.isCancellationRequested) {
return undefined;
}
Expand All @@ -47,6 +47,7 @@ export class DebugLauncher implements ITestDebugLauncher {
const deferred = createDeferred<void>();
debugManager.onDidTerminateDebugSession(() => {
deferred.resolve();
callback?.();
});
debugManager.startDebugging(workspaceFolder, launchArgs);
return deferred.promise;
Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface ITestConfigurationManagerFactory {
}
export const ITestDebugLauncher = Symbol('ITestDebugLauncher');
export interface ITestDebugLauncher {
launchDebugger(options: LaunchOptions): Promise<void>;
launchDebugger(options: LaunchOptions, callback?: () => void): Promise<void>;
}

export const IUnitTestSocketServer = Symbol('IUnitTestSocketServer');
Expand Down
7 changes: 5 additions & 2 deletions src/client/testing/testController/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class PythonTestServer implements ITestServer, Disposable {
return this._onDataReceived.event;
}

async sendCommand(options: TestCommandOptions): Promise<void> {
async sendCommand(options: TestCommandOptions, callback?: () => void): Promise<void> {
const { uuid } = options;
const spawnOptions: SpawnOptions = {
token: options.token,
Expand Down Expand Up @@ -158,7 +158,10 @@ export class PythonTestServer implements ITestServer, Disposable {
testProvider: UNITTEST_PROVIDER,
};
traceInfo(`Running DEBUG unittest with arguments: ${args}\r\n`);
await this.debugLauncher!.launchDebugger(launchOptions);

await this.debugLauncher!.launchDebugger(launchOptions, () => {
callback?.();
});
} else {
if (isRun) {
// This means it is running the test
Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/testController/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export type TestCommandOptionsPytest = {
*/
export interface ITestServer {
readonly onDataReceived: Event<DataReceivedEvent>;
sendCommand(options: TestCommandOptions): Promise<void>;
sendCommand(options: TestCommandOptions, callback?: () => void): Promise<void>;
serverReady(): Promise<void>;
getPort(): number;
createUUID(cwd: string): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,16 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
pytestRunTestIdsPort,
};
traceInfo(`Running DEBUG pytest with arguments: ${testArgs.join(' ')}\r\n`);
await debugLauncher!.launchDebugger(launchOptions);
await debugLauncher!.launchDebugger(launchOptions, () => {
deferred.resolve();
});
} else {
// combine path to run script with run args
const scriptPath = path.join(fullPluginPath, 'vscode_pytest', 'run_pytest_script.py');
const runArgs = [scriptPath, ...testArgs];
traceInfo(`Running pytests with arguments: ${runArgs.join(' ')}\r\n`);

await execService?.exec(runArgs, spawnOptions).catch((ex) => {
traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);
return Promise.reject(ex);
});
await execService?.exec(runArgs, spawnOptions);
}
} catch (ex) {
traceError(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {

// Send test command to server.
// Server fire onDataReceived event once it gets response.
this.testServer.sendCommand(options);
this.testServer.sendCommand(options, () => {
deferred.resolve();
});

return deferred.promise;
}
Expand Down