Skip to content

Commit

Permalink
fix bug so canceling debug works in rewrite (#21361)
Browse files Browse the repository at this point in the history
fixes #21336
  • Loading branch information
eleanorjboyd authored Jun 5, 2023
1 parent be829b3 commit a395e2e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
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, runTestIdPort?: string): Promise<void> {
async sendCommand(options: TestCommandOptions, runTestIdPort?: string, callback?: () => void): Promise<void> {
const { uuid } = options;
const spawnOptions: SpawnOptions = {
token: options.token,
Expand Down Expand Up @@ -146,7 +146,10 @@ export class PythonTestServer implements ITestServer, Disposable {
runTestIdsPort: runTestIdPort,
};
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, runTestIdsPort?: string): Promise<void>;
sendCommand(options: TestCommandOptions, runTestIdsPort?: string, 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 {
runTestIdsPort: 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 @@ -99,7 +99,9 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter {
runTestIdsPort = assignedPort.toString();
// Send test command to server.
// Server fire onDataReceived event once it gets response.
this.testServer.sendCommand(options, runTestIdsPort); // does this need an await?
this.testServer.sendCommand(options, runTestIdsPort, () => {
deferred.resolve();
});
})
.catch((error) => {
traceError('Error starting server:', error);
Expand Down

0 comments on commit a395e2e

Please sign in to comment.